Question

What will be the output of the following code snippet implementing the Least Recently Used (LR

  • U page replacement algorithm? def lru(pages, capacity):     page_frame = []     page_faults = 0     for page in pages:         if page not in page_frame:             if len(page_frame) < capacity:                 page_frame.append(page)             else:                 lru_page = min(page_frame, key=lambda p: pages.index(p))                 page_frame.remove(lru_page)                 page_frame.append(page)             page_faults += 1     return page_faults pages = [7, 0, 1, 2, 0, 3, 0, 4, 2, 3] capacity = 4 faults = lru(pages, capacity) print(faults)
A 7
B 5
C 8
D 6
E 4
Practice Next

Relevant for Exams:

Hey! Ask a query