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).
- Page 1: Page Fault (Fault 1)
- Page 2: Page Fault (Fault 2)
- Page 3: Page Fault (Fault 3)
- Page 4: Page Fault. Frames contain . 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 (Fault 4)
- Page 2: Hit
- Page 1: Hit
- Page 5: Page Fault. Frames contain . 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 (Fault 5)
- Page 3: Page Fault. Frames contain . Future references: 2 (pos 9), 4 (pos 10), 6 (pos 11). Page 5 is never referenced again, so replace 5 with 3 (Fault 6)
- Page 2: Hit
- Page 4: Hit
- Page 6: Page Fault. Frames contain . No future references remain, replace any frame (e.g., 3) (Fault 7)
Total number of page faults = 7.
7
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.