algorithms.tutorialhorizon.com
Least Recently Used (LRU) Cache – Using LinkedHashSet and Deque | Set 2 | Algorithms
Objective: Design and Implement a data structure Least Recently Used (LRU) Cache. Earlier we had seen Least Recently Used (LRU) Cache – Using HashMap and Doubly Linked List. In this article we will see the implementation using LinkedHashSet and Deque. Lets first brief about LRU- Given a cache (or memory) with capacity. The cache will be filled with items you will access or look for it. The most recently accessed item will be at the top of the cache whereas least recently used cache will be at the end of the cache. As you will access the items, the cache will be filled as per the conditions below If item is not present in the cache and cache capacity is NOT REACHED then item will be added at top of the cache. If item is not present in the cache and cache capacity is REACHED then least recently item from cache will be removed (the last element in cache) and new item will be added at top of the cache.If item is already present in the cache then it will moved to the top of the