Skip to content
Lesson 4 of 8

Step 1 of 5 · Reading · ~1 min

Read

The Doubly-Linked List + Hash Map

Combining: Hash Map + DLL

The classic O(1) LRU = hash map (key -> Node) + doubly-linked list (recency order).

python

Both get and put are O(1):

  • Hash map lookup: O(1)
  • DLL remove + add_front: O(1) (we have direct node pointers, no scan)
  • Eviction: O(1) (tail.prev is always the LRU)

This is THE classic LRU. Almost every production cache uses this structure.

Up nextThread-Safe LRUConcurrency

Discussion

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

Sign in to post a comment or reply.

Loading…