Saturday, March 5, 2011

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

3)Memory allocation:
Most often, arrays are static. The drawback to this approach is that large arrays require large amounts of memory, which may go unused.
On the other hand, linked lists are usually dynamic. They can grow and shrink as needed at runtime. Due to this trait, linked lists are more appealing when the number of elements is unknown.

4) Accessing elements:
The elements within arrays are accessed by their indices. Thus, data access is easy and fast if you know which element to retrieve. If you don’t know the index of the element needed, but the elements are sorted based on some key value, you can perform highly efficient search algorithms to locate specific elements.

Linked lists are usually traversed element by element until a match is found. Because the memory for linked lists is not guaranteed to be contiguous, this list traversal is the only method for searching the list (without involving the use of other data structures as indices ). 


5) Making the decision:
If your data is best represented using a multidimensional structure, or the number of elements is known in advance and will remain consistent, an array is best. If your data is easily represented in one dimension, and the number of elements is unknown or is expected to change often throughout the operation of your program, a linked list is more efficient.

also refer :
http://geeksforgeeks.org/?p=10245
http://geekexplains.blogspot.com/2008/05/array-vs-linked-list-advantages-and.html

No comments:

Post a Comment