We are given 10 physical frames and an access string of 40 page accesses containing 20 distinct pages repeated twice:
(a1,a2,…,a20,a1,a2,…,a20) ### 1. Last-In-First-Out (LIFO) Policy:
First 10 accesses (a1 to a10): Each page misses and is placed into an empty frame. Frame content: {a1,a2,…,a10}. (10 faults)
Next 10 accesses (a11 to a20):
a11 replaces a10 (the last inserted page). Frame: {a1,…,a9,a11}.
a12 replaces a11, and so on, until a20 replaces a19. Frame content at the end of the first pass: {a1,a2,…,a9,a20}. (10 faults)
Second pass (a1 to a20):
a1 through a9 are all hits because they remained in the first 9 frames (0 faults).
a10 misses and replaces a20. Frame: {a1,…,a9,a10}. (1 fault)
a11 through a20 all miss, each replacing the previously inserted page (10 faults).
Total faults for LIFO =10+10+0+1+10=31.
### 2. Optimal (OPT) Policy:
First 10 accesses (a1 to a10): All miss and fill the 10 frames (10 faults).
Accesses a11 to a20:
In the future, pages a1,…,a9 will be accessed earlier in the second pass than a10,a11,…
Thus, OPT always replaces the page that is needed furthest in the future. It can retain {a1,…,a9,a20} or any 10 pages for the second pass.
Each of a11,…,a20 causes a fault (10 faults).
Second pass:
Exactly 10 pages residing in frames will result in hits (a1,…,a9 and a20), while the remaining 10 pages fault (10 faults).
Total faults for OPT =10+10+10=30.
### Difference:
Difference=FaultsLIFO−FaultsOPT=31−30=1 Thus, the difference is 1.