Linked List Data Structure
A Linked List is a dynamic linear data structure used to store a collection of elements called nodes. Unlike arrays, linked lists do not store elements in contiguous memory locations. Instead, each node contains data and a pointer that connects it to the next node.
Linked lists are widely used because they allow dynamic memory allocation and efficient insertion and deletion operations.
Why Linked List Is Needed?
Arrays have some limitations such as:
- Fixed size
- Difficult insertion and deletion
- Memory wastage
Linked lists solve these problems because they:
- Grow dynamically during runtime
- Use memory efficiently
- Allow easy insertion and deletion
This makes linked lists useful in many computer science applications.
Structure of Linked List
Each node in a linked list contains two parts:
| Part | Description |
|---|---|
| Data | Stores the actual value |
| Pointer | Stores address of next node |
Example
[10 | * ] → [20 | * ] → [30 | NULL]Here:
- 10, 20, and 30 are data values
- Pointer connects nodes together
- NULL indicates the end of the linked list
Important Terminologies
1. Node
A node is the basic building block of a linked list.
Each node stores:
- Data
- Address of next node
2. Head
The head stores the address of the first node.
Example
Head → [10 | * ] → [20 | NULL]If the list is empty:
Head = NULL3. Tail
The last node of the linked list is called the tail.
The tail node points to NULL in a singly linked list.
Types of Linked List
1. Singly Linked List
In a singly linked list:
- Each node points to the next node only
- Traversal is possible in one direction
Example
10 → 20 → 30 → NULL2. Doubly Linked List
In a doubly linked list:
- Each node contains two pointers
- One points to previous node
- Another points to next node
Example
NULL ← 10 ⇄ 20 ⇄ 30 → NULL3. Circular Linked List
In a circular linked list:
- The last node connects back to the first node
- No NULL pointer exists at the end
Example
10 → 20 → 30
↑ ↓
└─────────┘Basic Operations on Linked List
Following are the basic operations supported by a linked list.
- Insertion − adds a new node into the linked list.
- Deletion − removes an existing node from the linked list.
- Traversal (Display) − displays all the nodes of the linked list.
- Searching − searches an element using a given key.
- Updating − modifies the value of an existing node.
- Sorting − arranges nodes in ascending or descending order.
- Reversing − changes the direction of the linked list.
Detailed algorithms and implementations of these operations are studied separately in linked list operations topics.
Advantages of Linked List
- Dynamic size
- Efficient insertion and deletion
- Better memory utilization
- Flexible data management
Linked lists are commonly used in:
- Stacks
- Queues
- Graphs
- Memory management systems
Disadvantages of Linked List
- Extra memory required for pointers
- Sequential access only
- Searching is slower compared to arrays
- Complex pointer handling
Linked List vs Array
| Feature | Array | Linked List |
|---|---|---|
| Size | Fixed | Dynamic |
| Memory Location | Contiguous | Non-contiguous |
| Access | Fast | Sequential |
| Insertion/Deletion | Difficult | Easier |
Applications of Linked List
Linked lists are widely used in many applications.
Common Applications
- Music playlist
- Browser history
- Undo and redo operations
- Process scheduling
- Memory management
- Image viewer
Conclusion
Linked List is one of the most important dynamic data structures in computer science. It overcomes the limitations of arrays by allowing flexible memory allocation and efficient data handling. Linked lists are widely used in operating systems, applications, and advanced data structures such as stacks, queues, trees, and graphs.