Which data structure is best suited for implementing LRU Cache?Singly Linked ListDoubly linked list with a hash mapCircular linked listArray
Question
Which data structure is best suited for implementing LRU Cache?
- Singly Linked List
- Doubly linked list with a hash map
- Circular linked list
- Array
Solution
The best data structure for implementing LRU (Least Recently Used) Cache is a Doubly Linked List with a Hash Map.
Here's why:
-
Doubly Linked List: This is used to store the keys of cache with the most recently used keys at the start of the list and the least recently used keys at the end. The advantage of using a doubly linked list is that it supports O(1) time complexity for all operations (insertion, deletion, moving an element to the start) if we have a direct reference to the node containing key.
-
Hash Map: This is used for supporting quick look-up (O(1) time complexity) to check if a key is present in the cache or not. The key in the hash map is the actual key and the value is the address of the node in the doubly linked list.
So, the combination of these two data structures provides an efficient way of implementing LRU Cache.
Similar Questions
Which of the following data structures can be efficiently implemented using Double Hashing?OptionsHash tablesLinked listsArraysBinary trees
Which data structure is known for its fast random access but has a fixed size once allocated?*1 pointa. Arrayb. Queuec. Linked List
To achieve fast data access, it is preferable to use:*1 pointLinked ListsArraysOther:
Which of the following are applications of linked lists?a.All of the aboveb.Chaining in hash tablesc.Implementing file systemsd.Binary tree implementation
The elements of a linked list are storeda.In a structureb.In an arrayc.Anywhere the computer has space for themd.In contiguous memory locations
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.