Virtual Memory & Paging

Answer & solution
Official answer: 1.0 : 1.0
Our answer: 1
Assume initially empty frames. Both policies fault on all 20 first-pass pages. LIFO retains a 1 through a 9 and the most recently inserted page a 20. The second pass hits on a 1..a 9 then faults on a 10..a 20, giving 31 faults total. OPT can retain a 1..a 9, a 20 after the first pass, then uses frames of already-consumed pages to service a 10..a 19 while retaining a 20, giving 30. At least 10 second-pass faults are unavoidable because only 10 of 20 distinct pages can initially be resident, so OPT is optimal. Difference 31−30=1.
Under LIFO, page hits do not change insertion order. Once frames fill with a1 through a 10, every first-pass fault replaces the newest page in the same slot; a1 through a9 remain throughout. In the second pass, these nine hit and the other eleven fault. OPT has ten resident pages at the start of the second pass and can fault on exactly the ten absent pages by discarding pages whose final reference has already occurred. The total faults are therefore 31 versus 30, not counts of distinct pages alone.