Browse Curriculum

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.
Unlock VisualizerPREMIUM FEATURE

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:
  1. Create new node.
  2. Set new node's next to current Head.
  3. Set current Head's prev to new node.
  4. 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.

Start Your Premium Prep