Final answer:
The optimal page-replacement algorithm is to replace the page that will not be used for a long time. This algorithm is known as the Least Recently Used (LRU) algorithm.
Step-by-step explanation:
The optimal page-replacement algorithm is to replace the page that will not be used for a long time. This algorithm is known as the Least Recently Used (LRU) algorithm. It works by keeping track of the order in which pages are accessed and replacing the page that was least recently used.
For example, let's say we have a cache memory with a capacity of 4 pages and the following page-reference string: 1, 2, 3, 4, 5, 1, 2, 6, 7, 8. Using the LRU algorithm, the cache would be populated as follows:
- 1 (Fault)
- 1, 2 (Fault)
- 1, 2, 3 (Fault)
- 1, 2, 3, 4 (Fault)
- 2, 3, 4, 5 (Fault)
- 3, 4, 5, 1 (Fault)
- 4, 5, 1, 2 (Fault)
- 5, 1, 2, 6 (Fault)
- 1, 2, 6, 7 (Fault)
- 2, 6, 7, 8 (Fault)
As you can see, the algorithm replaces the least recently used page.