Skip to content
DSA Visualizerpreview

LRU cache (doubly linked list + map)

A map finds any key's node at once; a doubly linked list keeps them in order of use.

O(1) per access time · O(capacity) space

Accesses1, 2, 3, 1, 4, 1, 2, 5, 1, 3capacity 3

An empty cache with room for 3. Each number below is an access to that key.

Cache of 3, most recent first: empty.
  • compare
  • swap or write
  • settled

1 / 19

Speed

Space play · ← → step · Home End jump · drag the strip to scrub