Linked list disadvantages
Drawbacks / Disadvantages of Linked List
1. Wastage of Memory -
- Pointer Requires extra memory for storage.
- Suppose we want to store 3 integer data items then we have to allocate memory -
in case of array -
Memory Required in Array = 3 Integer * Size = 3 * 2 bytes = 6 bytes
in case of array -
Memory Required in LL = 3 Integer * Size of Node = 3 * Size of Node Structure = 3 * Size(data + address pointer) = 3 * (2 bytes + x bytes) = 6 bytes + 3x bytes
*x is size of complete node structure it may vary
2. No Random Access
- In array we can access nth element easily just by using a[n].
- In Linked list no random access is given to user, we have to access each node sequentially.
- Suppose we have to access nth node then we have to traverse linked list n times.
Suppose Element is present at the starting location then -
We can access element in first Attempt
Suppose Element is present at the Last location then -
We can access element in last Attempt
3 . Time Complexity
- Array can be randomly accessed , while the Linked list cannot be accessed Randomly
- Individual nodes are not stored in the contiguous memory Locations.
- Access time for Individual Element is O(n) whereas in Array it is O(1).
4. Reverse Traversing is difficult
- In case if we are using singly linked list then it is very difficult to traverse linked list from end.
- If using doubly linked list then though it becomes easier to traverse from end but still it increases again storage space for back pointer.
5. Heap Space Restriction
- Whenever memory is dynamically allocated , It utilizes memory from heap.
- Memory is allocated to Linked List at run time if and only if there is space available in heap.
- If there is insufficient space in heap then it won’t create any memory.