When the cache is full, who gets evicted? Compare LRU, MRU, LFU, FIFO, and Clock replacement live.
5 algorithms
5 algorithms. Each one stands alone.
When full, drop the item used most recently.
O(1) per request time · O(capacity) spaceVisualizeWhen full, drop the item used the fewest times.
O(1) per request with frequency buckets time · O(capacity) spaceVisualizeWhen full, drop the item that came in first.
O(1) per request time · O(capacity) spaceVisualizeA hand sweeps the slots and gives used items a second chance.
O(1) per request time · O(frames) spaceVisualizeA cache keeps a few items close at hand so the next request for them is fast, and it always runs out of room. The question these pages answer is which item to throw out when a new one needs space. CPUs, operating systems, databases, browsers and content delivery networks all face it, and the LRU cache is one of the most asked design problems in interviews.
Every policy here is a bet about the future made from the past: on a miss with the cache full, pick a victim. All five pages play the same twelve requests, 1 2 3 4 1 2 5 1 2 3 4 5, into four slots, so their hit counts compare directly: FIFO 2, Clock 2, LRU 4, LFU 4 and MRU 6. The only thing that changes from page to page is the rule for choosing what leaves.
Do not pick a policy from one sequence. MRU wins here because the requests loop, and it would throw out the hottest item on ordinary traffic. Ask what your access pattern looks like: recent reuse points to LRU or Clock, steady favourites to LFU, long repeating scans to MRU, and little reuse at all to FIFO.