Data Structures & AlgorithmsVery hardGATE CS · Infosys

An LRU cache holds 3 keys. Requests arrive in the order 1, 2, 3, 1, 4, 2, 5, 1, 2, 3, 4, 5, and a request for an absent key is a miss that inserts it (evicting the least recently used key when full). How many misses occur?

  1. A. 10
  2. B. 12
  3. C. 5
  4. D. 2

Correct answer: A. 10

Simulating LRU with 3 frames, only the 4th request (1) and the 9th (2, just reloaded) are hits, so 12 − 2 = 10 misses. 12 assumes nothing is ever reused, 5 counts only the compulsory first-time misses, and 2 is the number of hits, not misses.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic