If McDonalds were run like a software company, one out of every hundred Big Macs would give you food poisoning, and the response would be, ‘We’re sorry, here’s a coupon for two more.’ “ Mark Minasi

LRU cache

Language Java | Level Intermediate | Category Algorithms | August 4, 2015 8:42 am


Algorithm Problem Description

LRU cache algorithm discards the least recently used items first. This algorithm requires keeping track of what was used when, which is expensive if one wants to make sure the algorithm always discards the least recently used item.

Write a program to implement LRU Cache.

Output

          	        
          	        

LRU Cache unitized with size 5
Display LRU:
[10]= [20]
[9]= [18]
[8]= [16]
[7]= [14]
[6]= [12]

LRU Cache after retrieving 7
[7]= [14]
[10]= [20]
[9]= [18]
[8]= [16]
[6]= [12]

LRU cache on adding one more item. It will replace last one
[11]= [22]
[7]= [14]
[10]= [20]
[9]= [18]
[8]= [16]

          	        
          	        				    


Comments



Please login to add comments.