Overview & Concept
A Doubly Linked List is a linear collection of nodes where each node contains two pointers: "next" pointing to the successor and "prev" pointing to the predecessor. This bidirectional linkage enables efficient bidirectional traversal, O(1) removal of known nodes without preceding node search, and serves as the core foundation for LRU caches and deque structures.
How It Works
Bidirectional Pointers: Each node stores both next and prev references.
Head and Tail Tracking: Pointers to both ends allow instant O(1) push and pop at both boundaries.
O(1) Node Self-Deletion: Given a pointer to node X, removing X is done directly by X.prev.next = X.next and X.next.prev = X.prev.
Bidirectional Traversal: Can iterate forwards from head or backwards from tail.
Step-by-Step Execution
Asymptotic Complexity Analysis
| Metric | Best Case | Average Case | Worst Case | Space Complexity |
|---|---|---|---|---|
| Complexity Bound | O(1) push/pop ends | O(n) index access | O(n) traversal | O(n) |
| Explanation | Optimal input arrangement minimizing operations. | Expected time for uniformly distributed randomized inputs. | Adversarial degenerate conditions requiring full traversal. | Auxiliary memory allocated beyond original input size. |
Pseudocode & Invariants
// Doubly Linked List Operations operation deleteNode(node): if node.prev != null: node.prev.next = node.next else: head = node.next if node.next != null: node.next.prev = node.prev else: tail = node.prev free(node)
- Bidirectional Consistency: For every node X where X.next != null: X.next.prev == X.
- Boundary Invariants: head.prev == null and tail.next == null.
Advantages & Disadvantages
Key Advantages
- •Bidirectional traversal in both directions from head or tail.
- •O(1) deletion of an arbitrary node given its direct reference.
- •O(1) insertion before or after any referenced node.
Trade-offs & Limitations
- •Increased memory overhead: 2 pointers (prev, next) per node.
- •More complex pointer management: every insertion/deletion requires 4 pointer updates.
Real-World Applications
LRU (Least Recently Used) Cache
Combined with a Hash Map to achieve O(1) get and O(1) eviction of stale items.
Browser Tab & History Navigation
Back and forward page navigation history in web browsers.
Music Playlist Players
Seamless skip forward and skip previous track transitions.
Decision Guide: When to Use
Ideal Scenarios
- ✓When bidirectional traversal is required.
- ✓When implementing LRU caches, Deques, or complex buffer managers.
Consider Alternatives When
- ✕When memory per node is tightly constrained and unidirectional traversal suffices.
Explore Related Algorithms
Compare trade-offs and complexity across complementary tools in AlgoViz.