Skip to content
Naive LRU: List Scan
step 1/5

Reading — step 1 of 5

Read

~1 min readWhy LRU

Naive LRU: List Scan

Simplest LRU: store entries in a list, ordered most-recent-first.

python

Works! But:

  • get: O(n) — scan the list
  • put: O(n) — same
  • Insert at front of a list: O(n) for arrays

For a million-entry cache, every operation is a million-comparison search. Unusable.

Real LRU achieves O(1) per operation. Trick: combine a hash map (O(1) lookup) with a doubly-linked list (O(1) move-to-front).

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…