Home
DSA Course
Data Structures
Doubly Linked List
Doubly Linked List
Each node has two pointers: one to the next node and one to the previous node.
Empty List
Ready
See the Logic in Motion
Stop memorizing code. Unlock the full interactive visualizer to master the logic step-by-step.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
Insert at Head:
- 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.
Stop Guessing, Start Mastering.
Build the FAANG intuition. Master this pattern with optimized implementations, visual dry runs, and our curated collection of high-yield problems.
