Linked List
A linked list is a collection of nodes stored randomly in the memory. The nodes contain two fields:
- Data stored at a specified address.
- A pointer to the address of the next node.
Uses of a linked list:
- Linked lists help to optimize the utilization of space as they are not required to be continuously present in the memory.
- It need not be declared early hand as it is limited to the size of the memory.
- The value of primitive types or objects can be stored in the singly linked list.
- There are no empty nodes in the linked list.
Why linked list is better than an array?
An array has the following limitations:
- The size of the array must be known beforehand.
- It requires a long time to increase the size of the array.
- There is no optimized utilization of space as the elements need to be continuously present in the memory.
Reference
