DSA Basics: Doubly Linked List

Learn how doubly linked lists use next and previous links for two-way traversal.

Back to Learn DSA

A doubly linked list is a linked list where each node points in two directions.

Each node stores:

null <- [12] <-> [24] <-> [36] -> null

Why add prev?

A singly linked list can only move forward. A doubly linked list can move forward and backward.

That extra link makes some operations easier, but each node uses more memory and every mutation must update two directions correctly.

Insert between two nodes

function insertBetween(left, right, node) {
	node.prev = left;
	node.next = right;
	left.next = node;
	right.prev = node;
}

Where doubly linked lists show up

Complexity

Use the visualizer below to move in both directions.

Interactive walkthrough

Doubly Linked List Traversal

Move forward and backward using next and prev links.