📝 Optimal page replacement (9 MCQs)
Future-Reference Knowledge in Optimal Replacement
Optimal page replacement is a theoretical memory-management algorithm that removes the resident page whose next reference is farthest in the future, or that will never be referenced again. It minimises page faults for a known reference string and fixed frame allocation. Because real operating systems cannot know future program behaviour, the algorithm primarily serves as an ideal benchmark for evaluating practical replacement policies.
Why Future Knowledge Establishes a Performance Benchmark
Replacement algorithms attempt to predict which pages will remain useful after the current reference. Historical information can provide an estimate, but it cannot guarantee future behaviour. Optimal replacement removes the page that causes the least expected future disruption because its next use is most distant. Its theoretical result establishes the minimum possible page-fault count for the given reference sequence.
Finding the Page with the Farthest Next Reference
On a page fault with all frames occupied, examine the remaining reference string for each resident page. Determine the next position at which each page appears. Replace the page whose next use is farthest away, treating a page that never appears again as an especially suitable victim. Continue the same procedure for every subsequent reference.
Choosing a Victim from Three Resident Pages
Suppose the frames contain pages 1, 2, and 3, and the remaining reference sequence is 2, 4, 1, 5, 3. Page 2 is needed immediately, page 1 appears next, and page 3 appears last. When page 4 arrives, optimal replacement removes page 3 because its next reference occurs farthest in the future.
Minimum Fault Count and Practical Limitations
Optimal replacement provides the lowest theoretically achievable number of page faults for a particular reference string and frame allocation. However, future references are unavailable to ordinary operating systems during execution. Its practical value is therefore comparison rather than direct implementation. Researchers and students use it to measure how closely FIFO, LRU, and approximation algorithms approach ideal replacement performance.
Misunderstandings About Future Page References
'Optimal replacement selects the least recently used page' is incorrect because its decision depends on future references. 'The operating system normally knows the complete future reference string' is incorrect because actual program behaviour is not generally predictable. 'Optimal replacement always selects the page with the largest page number' is incorrect because selection depends exclusively on future use.
Exam Focus: Finding the Optimal Victim
For each fault, inspect the remaining reference string and identify the resident page whose next use is farthest away. Treat pages that are never referenced again as eligible victims. Calculate the total fault count for the specified frame capacity, then compare it with FIFO or LRU. Remember that an optimal trace requires knowledge of future references.
Key Terms of Optimal Replacement
- Optimal algorithm - Minimises page faults.
- Future reference - Subsequent page access.
- Victim page - Selected page for removal.
- Reference string - Ordered sequence of page accesses.
- Benchmark - Standard for performance comparison.
- Minimum fault count - Lowest achievable faults.
📝 All Optimal page replacement MCQs
Q1. A program accesses pages in the order 1,2,3,4,1,2,5,1,2,3,4,5 and the system has three page frames. Using the optimal page‑replacement algorithm, how many page faults occur?
📖 Explanation: The optimal algorithm looks ahead to see when each resident page will be used next. Starting with three empty frames, faults happen on references 1,2,3,4,5,3,4, giving a total of seven. Option B matches this count. Options A, C, and D are incorrect because they underestimate or overestimate the required faults. This illustrates how optimal replacement minimizes faults by evicting the page whose next use is farthest in the future, which directly reduces unnecessary swaps.
Q2. Why is the optimal page‑replacement algorithm considered impractical for real operating systems?
📖 Explanation: The optimal algorithm assumes the system knows every future page request, which is impossible in practice; therefore it cannot be implemented. Option A states this requirement. Options B, C, and D describe unrelated constraints: the algorithm works with any number of frames, deals with individual pages, and uses the same valid‑invalid bits as other policies. Understanding this limitation explains why heuristics like LRU are used instead of the theoretically perfect algorithm.
Q3. What is the definition of the optimal page‑replacement algorithm in demand‑paging systems?
📖 Explanation: The optimal algorithm selects the page that will not be needed for the longest period of time, i.e., whose next reference is farthest away, guaranteeing the fewest faults. Option B captures this definition. Options A and C describe FIFO and random policies, respectively, while D is arbitrary and unrelated. Recognizing the optimal criterion helps students compare it with practical approximations such as LRU or CLOCK.
Q4. A system has four page frames and accesses pages in the order 7,0,1,2,0,3,0,4,2,3,0,3,2. When the reference to page 4 occurs, which page will the optimal algorithm evict?
📖 Explanation: At the moment of the reference to 4, the frames contain {7,0,1,2}. Looking ahead, page 7 never appears again, while 0 appears soon, 1 never appears again, and 2 appears later. The optimal choice is to evict a page with the farthest future use; both 7 and 1 qualify, but the algorithm may evict 7. Option D reflects this decision. The other options incorrectly assume nearer‑future pages are removed.
Q5. How does the optimal page‑replacement algorithm relate to Belady’s anomaly, the phenomenon where increasing the number of frames can increase page faults?
📖 Explanation: Belady’s anomaly occurs with sub‑optimal policies like FIFO; the optimal algorithm, by definition, produces the smallest possible fault count for each frame configuration, so the anomaly cannot appear. Option B states this property. Options A and C incorrectly suggest the optimal algorithm can suffer the anomaly, and D mischaracterizes the relationship. Understanding this connection underscores why optimal replacement is a theoretical benchmark.
Q6. A workload causes 15 page faults under the optimal algorithm and 25 faults under FIFO. If each page‑in from disk takes 10 ms, what is the total reduction in swap‑in time (in milliseconds) when using the optimal algorithm?
📖 Explanation: Each fault requires a 10 ms disk read. Optimal: 15 × 10 = 150 ms; FIFO: 25 × 10 = 250 ms. The difference is 250 − 150 = 100 ms, so option C is correct. Options A, B, and D give incorrect differences. This calculation shows how an algorithm that reduces faults directly cuts I/O latency, which is crucial for system performance when disk access dominates execution time.
Q7. Why does the optimal page‑replacement algorithm guarantee the smallest possible number of page faults among all deterministic algorithms?
📖 Explanation: The optimal algorithm’s guarantee follows from its look‑ahead rule: by removing the page whose next use is farthest away, it ensures that no other deterministic choice could produce fewer future faults. Option B correctly describes this reasoning. Options A and C describe unrelated strategies, and D merely mentions a hardware mechanism that does not affect the replacement decision. This principle forms the basis for evaluating other policies.
Q8. For the reference string 1,2,3,4,1,2,5,1,2,3,4,5 with three page frames, what is the difference in the number of page faults between the optimal algorithm and LRU?
📖 Explanation: Using optimal replacement yields 7 faults, while LRU produces 10 faults for the same string and frame count. The difference is therefore 10 − 7 = 3, matching option B. Options A, C, and D give incorrect differences. This comparison demonstrates how an optimal policy can substantially outperform a common heuristic, highlighting the impact of replacement choices on overall fault rates.
Q9. Using the optimal algorithm for a two‑level memory hierarchy where the cache holds 2 pages, how many cache misses occur for the reference string 1,2,3,4,1,2,5,1,2,3,4,5?
📖 Explanation: Tracking the cache with optimal decisions gives misses at references 1,2,3,4,2,5,2,3,4, totaling nine misses. Option D reflects this count. Options A‑C underestimate the misses by ignoring optimal evictions in later steps. This scenario shows how even with optimal replacement, a small cache can still incur many misses, emphasizing the importance of cache size in performance.