1

Can anyone give two examples for LRU and LFU?

1.bad for LRU and good for LFU

2.good for LRU and bad for LFU?

Fanny ZMN
  • 73
  • 1
  • 7

3 Answers3

2
  1. LRU bad LFU good

    example can be found here: https://stackoverflow.com/a/29225598/7839693

  2. LRU good LFU bad

Let's consider a modified version of that example:

A, B, C, A, A, A, A, B, B, B, B, C, D, C

With LRU we would get something like:

[A]
[A, B]
[A, B, C]
[B, C, A] <- a stream of As keeps A at the head of the list.
[C, A, B] <- a stream of Bs keeps B at the head of the list.
[A, B, C]
[B, C, D] <- here, we evict A
[B, C, D]
[B, D, C]

However, with LFU we would keep A and B, which would result in evicting C and D, which can be seen here:

[A]
[A, B]
[A, B, C]
[A, B, C] <- a stream of As makes the frequency of A = 5
[A, B, C] <- a stream of Bs makes the frequency of B = 5
[A, B, C] <- C = 2
[A, B, D] <- here, we evict C because it has the lowest frequency
[A, B, C] <- here, we evict D because it has the lowest frequency

We ended up evicting C and D with LFU compared to LRU, where we kept D and C

Community
  • 1
  • 1
0
  • LRU , LFU are page replacement algorithms in os . It scedules the manner in which the pages are swapped out and swapped in memory !!!
  • "Least Frequently Used" is the best polycy for page replacement in os !!!

  • LRU (Least recently used): the process to wich CPU will assign will be the one which is least recently used, in active processes queue.

  • LFU (Least frequently used): the process to wich CPU will assign will be the one which is least frequently used, in active processes queue.

  • LRU is a cache eviction algorithm called least recently used cache.
RïshïKêsh Kümar
  • 4,734
  • 1
  • 24
  • 36
0
  • the main difference is that in LRU we only check on which page is recently that used old in time than other pages i.e checking only based on recent used pages. BUT in LFU we check the old page as well as the frequency of that page and if frequency of the page is lager than the old page we cant remove it and if we all old pages are having same frequency then take last i.e FIFO method for that. and remove page....
RïshïKêsh Kümar
  • 4,734
  • 1
  • 24
  • 36