Browse curriculum

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

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.

Applying for software engineering roles? Free, no sign-up:

AI resume checker — match your resume to the job description

Frequently Asked Questions

What is a Doubly Linked List?

A Doubly Linked List is a linked list where each node contains pointers to both the next node and the previous node.


Singly vs Doubly Linked List?

Doubly Linked Lists allow for two-way traversal and easier deletion of a node (if given a pointer to it), but they require more memory for the additional pointer.


Real-world examples of Doubly Linked Lists?

They are used in music player playlists (next/previous song), browser cache management (LRU cache), and UNDO/REDO operations.