Facilities of Array:

1.    ARRAY IS RANDOM: Since the elements of array are contiguous, thus any elements of array could be accessed randomly, accession of elements only requires the index of the element and the base address of the array, the address would be calculated using address arithmetic.

2.    ARRAY IS SIMPLE: Array is simple to program with, we don’t need any effort to manage the array in memory, no address manipulation, no additional maintenance is required.

Pitfall of ARRAY:

1.    ALLOCATION NOT GURANTEED: Since array is contiguous allocation thus, in run-time required memory may not be available contiguously for the successful allocation of array. If the no of elements to be processed is huge, then we cannot reply on array, as the allocation may turn into a failure.

2.    POOR MEMORY UTILIZATION: As we need to mention the size of the array while allocating the array, thus in run-time there may be a shortage or wastage of elements.

3.    POOR DYNAMIC BEHAVIOUR: Its tedious to insert or remove elements from an array in run-time…It requires reallocation of the array and copying from the old to new location and thus slows down the whole process.

Facilities Of Linked List:

1.    ALLOCATION OF ELEMENT GURANTEED: In linked list the elements are inserted “AS AND WHEN REQUIRED” basis dynamically, that is, when an element is required to be stored we allocate an element dynamically and insert the element into the linked list. Thus, if there is sufficient space to store at least one element, we can allocate an element.

2.    SMART MEMORY UTILIZATION: We do not need to mention the no of elements while starting with a linked list. Dynamically elements could be created and inserted into the linked list, thus as long as memory is available no shortage would be there, and with linked list the is no question of wastage elements. If an element is not required it is removed from the list and the dynamic memory is returned to free-store of the operating system.

3.    SMART MEMORY MANAGEMENT: Elements could be inserted and removed anywhere in the linked list. Only it requires address manipulation.

Pitfall of Linked List:

1.    SEQUENTIAL ACCESS: Each element of linked list contains the address of the next element in the list, as the elements are allocate dynamically in discrete order thus the elements most obviously may not be contiguous in the memory. The head/start pointer of the linked list holds the address of the first element, thus if we need to access the nth element of the linked list we need to traverse all n-1 th elements.

2.    NOT SO SIMPLE: It’s not simple-to-use like data-structure like array. In linked list each specific operation needs to be explicitly written by the programmer, no automatic memory management or manipulation is there for linked list.

Conclusion:

Both array and linked list are suitable data-structure depending on the situation of use and how they are used practically. In array we get the random access of the elements by sacrificing the memory efficiency on the other hand in linked list we have better and efficient utilization of memory but sacrificing the randomness, we need to access the elements in sequence in linked list. Like everywhere, Tradeoff Prevails.

Advertisements