![]() |
VOOZH | about |
Linked List is a linear data structure, in which elements are not stored at a contiguous location, rather they are linked using pointers. Linked List forms a series of connected nodes, where each node stores the data and the address of the next node.
Node Structure: A node in a linked list typically consists of two components:
Head and Tail: The linked list is accessed through the head node, which points to the first node in the list. The last node in the list points to NULL or nullptr, indicating the end of the list. This node is known as the tail node.
The main cases where we prefer linked list over arrays is due to ease of insertion and deletion in linked list
Example:
In a system, if we maintain a sorted list of IDs in an array id[] = [1000, 1010, 1050, 2000, 2040].
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).
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 due to this so much work is being done which affects the efficiency of the code.
Please refer Applications, Advantages and Disadvantages of Linked List for more detailed use cases of linked list. Also, refer Types of Linked List to know about different types of linked lists for different applications.
Please refer Complexity Analysis of Linked List for time complexities of different operations of linked list.