For the following page reference string 4,3,2,1,4,3,5,4,3,2,1,5, the number of…

2022

For the following page reference string 4,3,2,1,4,3,5,4,3,2,1,5, the number of page faults that occur in Least Recently Used (LRU) page replacement algorithm with frame size 3 is

  1. A.

    6

  2. B.

    8

  3. C.

    10

  4. D.

    12

Attempted by 144 students.

Show answer & explanation

Correct answer: C

Reference string: 4, 3, 2, 1, 4, 3, 5, 4, 3, 2, 1, 5. Frame size = 3. We simulate the Least Recently Used (LRU) replacement and count page faults.

  1. Step 1, reference 4: frames = [4, -, -]; page fault (total faults = 1).

  2. Step 2, reference 3: frames = [4, 3, -]; page fault (total faults = 2).

  3. Step 3, reference 2: frames = [4, 3, 2]; page fault (total faults = 3).

  4. Step 4, reference 1: 1 is not in frames. The least recently used page is 4 (used at step 1), so replace 4 → frames = [1, 3, 2]; page fault (total faults = 4).

  5. Step 5, reference 4: 4 is not in frames. LRU among [1, 3, 2] is 3 (used at step 2), replace 3 → frames = [1, 4, 2]; page fault (total faults = 5).

  6. Step 6, reference 3: 3 is not in frames. LRU among [1, 4, 2] is 2 (used at step 3), replace 2 → frames = [1, 4, 3]; page fault (total faults = 6).

  7. Step 7, reference 5: 5 is not in frames. LRU among [1, 4, 3] is 1 (used at step 4), replace 1 → frames = [5, 4, 3]; page fault (total faults = 7).

  8. Step 8, reference 4: 4 is in frames [5, 4, 3]; hit (no page fault, total faults = 7). Update recency of 4.

  9. Step 9, reference 3: 3 is in frames [5, 4, 3]; hit (no page fault, total faults = 7). Update recency of 3.

  10. Step 10, reference 2: 2 is not in frames. Current recency: 5 (used step 7), 4 (step 8), 3 (step 9); LRU is 5 → replace 5 → frames = [2, 4, 3]; page fault (total faults = 8).

  11. Step 11, reference 1: 1 is not in frames. Current recency: 2 (step 10), 4 (step 8), 3 (step 9); LRU is 4 (earliest) → replace 4 → frames = [2, 1, 3]; page fault (total faults = 9).

  12. Step 12, reference 5: 5 is not in frames. Current recency: 2 (step 10), 1 (step 11), 3 (step 9); LRU is 3 (earliest) → replace 3 → frames = [2, 1, 5]; page fault (total faults = 10).

Total page faults: 10

Key idea: On every access update the recency; on a miss replace the page that was not used for the longest time. Following this rule for the given sequence with three frames yields 10 faults.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Mppsc Assistant Professor