0
831views
What are the advantages of using linked lists over arrays
1 Answer
0
1views
  1. Following are the points in favour of Linked Lists.
    1. The size of the arrays is fixed: So we must know the upper limit on the number of elements in advance. Also, generally, the allocated memory is equal to the upper limit irrespective of the usage, and in practical uses, upper limit is rarely reached.
    2. Inserting a new element in an array of elements is expensive, because room has to be created for the new elements and to create room existing elements have to shifted.
    3. For example, suppose we maintain a sorted list of IDs in an array id[]. id[] = [1000, 1010, 1050, 2000, 2040, …..]. And if we want to insert a new ID 1005, then to maintain the sorted order, we have to move all the elements after 1000 (excluding 1000).
    4. Deletion is also expensive with arrays until unless some special techniques are used. For example, to delete 1010 in id[], everything after 1010 has to be moved.
    5. In a linked list, new elements can be stored anywhere in the memory unlike arrays where memory needs to be contiguous in nature.
    6. In array, Insertion and Deletion operation takes more time, as the memory locations are consecutive and fixed whereas in case of linked list, a new element is stored at the first free and available memory location, with only a single overhead step of storing the address of memory location in the previous node of linked list.hence Insertion and Deletion operations are fast in linked list.
    7. In arrays, Memory is allocated as soon as the array is declared, at compile time whereas in linked list, Memory is allocated at runtime, as and when a new node is added. It's also known as Dynamic Memory Allocation.
Please log in to add an answer.