1 of 4

Your RightSignal

Data structures · 3 of 111 / 3

Linked lists

The concept

A treasure hunt where each clue says where the next one is

A linked list stores items wherever there is free memory, and each item carries the address of the next one. Each item is called a node: a value plus a pointer, which is just the memory address of the next node.

Take the list 3 → 8 → 5. A pointer called the head leads to the node holding 3; 3 points to 8, 8 to 5, and 5 to null, a 'nothing' value marking the end. Like a treasure hunt, you reach 5 only by following clues from the start.

Unlike an array's items, nodes aren't side by side, so item k's address can't be computed: reaching it takes k − 1 hops, which is O(n). A doubly linked list adds a pointer back to the previous node, so you can walk both ways.