Question
What will be the output of the following code snippet
implementing the Least Recently Used (LRU) 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)Solution
In the LRU page replacement algorithm, when a page fault occurs and the page is not in the page frame, the algorithm replaces the least recently used page. In the provided code, the sequence of page requests is [7, 0, 1, 2, 0, 3, 0, 4, 2, 3] with a capacity of 4. The pages that cause faults are 7, 0, 1, 2, 3, and 4, leading to a total of 6 page faults throughout the execution. Why Other Options Are Wrong: A) 7: This option is incorrect as it counts one additional fault that does not occur in the given page sequence. B) 5: This option is incorrect as it undercounts the number of faults that occur during the execution. C) 8: This option is incorrect as it overcounts the faults; only 6 pages lead to faults based on the implemented logic. E) 4: This option is incorrect because it suggests that only four pages caused faults, which does not reflect the sequence provided.
Shalini is younger than Rashi by 4 years. If the ratio of Shalini and Rashi ages is 8:9 respectively, then find the age of Shalini.
The current ratio of the ages of 'Armaan' and 'Bittu' is such that six years from now, it will be 5:4, respectively. Presently, 'Chetna's age exceeds 'B...
- The ratio of the present ages of P to Q is 4:3 respectively. If the age of P two years ago is same as the age of Q three years hence, then find the present...
- Five years from now, the sum of the ages of ‘X’ and ‘Y’ will be 50 years. Ten years ago, ‘X’ was 8 years younger than ‘Y’. What will be the...
- The current age ratio of Riya to Simran is 5:2. In eight years, Riya’s age will be twice Simran’s age at that time. What is Riya’s present age?
A girl’s age is 145% of what it was 8 years ago, but 65% of what it will be after 8 years. What is her present age?
The ratio of the ages of A and B is 4:5. 6 years ago, the ratio of their ages was 3:4. Find their present ages.
The current age of Lisa is three times that of Maya. 5 years from now, Lisa's age will be twice the age of Tom at that time. If Maya is 3 years younger ...
Downstream speed of a boat is (8/7)th of the speed of the boat in still water. Find the time taken by the boat to cover 280 km downstream if it covers 2...
The average age of (x + 4) students is 14 years. When a tutor aged 30 years is included, the average increases by 1 year. Find x% of 900.