Saturday, March 5, 2011

DS- link list v/s array ( page 1)

Arrays and linked lists are among the most common data structures, and each is applicable in different situations.

1) An array is an ordered arrangement of data elements that are accessed by their referencing indices.
A linked list is a group of items, each of which contains a pointer pointing to the next item.


2)Sizing:
Arrays can be one-dimensional or multidimensional, depending upon your requirements. For example, you could use a one-dimensional array to store the scores of all students in a class for one test. A multidimensional array would be better to store the scores of all students for all tests throughout the semester. Figure A provides an example of a one-dimensional array, and Figure B shows a multidimensional array.

Figure A
One-dimensional array


Figure B
Multidimensional array


In Figure B, the scores may be averaged by test (across), by student (down), or by class (entire array), while each unique score is maintained.

In contrast to arrays, linked lists are, by their very nature, one-dimensional. They can be singly linked lists, as shown in Figure C, where traversal of the list can be done in only one direction, or doubly linked lists, such as in Figure D, where each element points to both the previous element and the next element in the list.

Figure C
Singly linked list

No comments:

Post a Comment