Home
DSA Visualizer
Data Structures
Doubly Linked List
Doubly Linked List
A doubly linked list is a linked list in which each node has two pointers: one to the next node and one to the previous node.
0 / 8 NODES
READY
List is empty
Insert a value to begin. Each node holds a value and a reference to the next one.
At
Value
Intuition
Like a train where each car is connected to the one in front AND the one behind. You can walk from the engine to the caboose and back.
Concept
A Doubly Linked List allows traversal in both directions. Each node contains data, a next pointer, and a prev pointer.
How it Works
- Prev Pointer: Points to the previous node.
- Bidirectional: Can traverse forward and backward.
- Memory: Requires more memory than Singly Linked List for the extra pointer.
Step-by-Step Breakdown
- Create new node.
- Set new node's
nextto current Head. - Set current Head's
prevto new node. - Update Head to new node.
When to Use
- Backward Traversal: When you need to navigate back and forth (e.g., Browser History, Music Player).
- Deletion: Deleting a given node is O(1) if you have the pointer to it.
When NOT to Use
- Memory Constraints: Extra pointer takes more space.
- Complexity: More pointers to update during insertion/deletion.
How to Identify
Problems requiring backward traversal or O(1) deletion of a known node.
Applying for software engineering roles? Free, no sign-up:
