algo·visual

Singly Linked List

Data Structures
avgO(n)worstO(n)spaceO(n)
12
head
27
8
41

A list of 4 nodes; head points at 12

1 / 45
Starting contents4 values
Operations6 / 40
  1. 1. insert(33 @ 2)
  2. 2. insert(5 @ 0)
  3. 3. search(41)
  4. 4. delete(27)
  5. 5. insert(19)
  6. 6. delete(99)

How it works

Each node stores a value and a pointer to the next node, so inserting or deleting rewires a pointer or two instead of shifting elements. The price is access: reaching position i means walking i links from the head.

Complexity

Best
O(1)
Average
O(n)
Worst
O(n)
Space
O(n)

Search algorithms

Jump to any algorithm or page