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?
- A. 10
- B. 12
- C. 5
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Given the linked list 1 -> 2 -> ... -> 8, the list is reversed in consecutive groups of 3 (a final group with fewer than 3 nodes is left…
- A linked list has a tail of 3 nodes leading into a cycle of 5 nodes. A slow pointer advances 1 node per step and a fast pointer advances 2…
- How many index pairs i < j satisfy (a[i] + a[j]) mod 7 = 0 for the array [3, 4, 7, 10, 11, 14, 21, 5, 9]?
- How many index pairs i < j satisfy a[i] XOR a[j] = 6 for the array [1, 4, 7, 2, 5, 3, 6]?
- How many contiguous subarrays of [3, -1, 2, -2, 4, -3, 1] have sum exactly 2?
- What is the length of the longest contiguous substring of the binary string 1100101101 that contains equal numbers of 0s and 1s?