Question

Assume that there are 3 page frames which are initially empty. If the page reference string is 1, 2, 3, 4, 2, 1, 5, 3, 2, 4, 6, the number of page faults using the optimal replacement policy is__________.

Official answer and solution
Official answer
7
From
Official GATE 2014 answer key

Solution

Simulate the Optimal page replacement algorithm on the reference string with 3 page frames.

Reference string: 1, 2, 3, 4, 2, 1, 5, 3, 2, 4, 6
Number of frames = 3 (initially empty).

  1. Page 1: Page Fault   ⟹  [1]\implies [1] (Fault 1)
  2. Page 2: Page Fault   ⟹  [1,2]\implies [1, 2] (Fault 2)
  3. Page 3: Page Fault   ⟹  [1,2,3]\implies [1, 2, 3] (Fault 3)
  4. Page 4: Page Fault. Frames contain {1,2,3}\{1, 2, 3\}. Future references: 2 (at pos 5), 1 (at pos 6), 3 (at pos 8). Page 3 is referenced farthest in future, so replace 3 with 4   ⟹  [1,2,4]\implies [1, 2, 4] (Fault 4)
  5. Page 2: Hit   ⟹  [1,2,4]\implies [1, 2, 4]
  6. Page 1: Hit   ⟹  [1,2,4]\implies [1, 2, 4]
  7. Page 5: Page Fault. Frames contain {1,2,4}\{1, 2, 4\}. Future references: 3 (pos 8), 2 (pos 9), 4 (pos 10), 6 (pos 11). Page 1 is never referenced again, so replace 1 with 5   ⟹  [5,2,4]\implies [5, 2, 4] (Fault 5)
  8. Page 3: Page Fault. Frames contain {5,2,4}\{5, 2, 4\}. Future references: 2 (pos 9), 4 (pos 10), 6 (pos 11). Page 5 is never referenced again, so replace 5 with 3   ⟹  [3,2,4]\implies [3, 2, 4] (Fault 6)
  9. Page 2: Hit   ⟹  [3,2,4]\implies [3, 2, 4]
  10. Page 4: Hit   ⟹  [3,2,4]\implies [3, 2, 4]
  11. Page 6: Page Fault. Frames contain {3,2,4}\{3, 2, 4\}. No future references remain, replace any frame (e.g., 3)   ⟹  [6,2,4]\implies [6, 2, 4] (Fault 7)

Total number of page faults = 7.

Final answer

7

Common trap

Using LRU (looking back) instead of Optimal (looking forward).

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2014 Computer Science and Information Technology (CS) Session 1
Question
43 of 65, printed as CS Q.33
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.