Skip to content
Part IA Lent Term

Page-Replacement: Worked Examples

Worked example 1: OPT on 1 2 3 2 4 3 5 1 3 2 3 4 (2024 Q4)

Three frames. OPT replacement: evict the page whose next use is farthest in the future.

StepRefFrames afterFault?Evicted?Reason
11[1]YesFirst load
22[1, 2]YesFirst load
33[1, 2, 3]YesFirst load
42[1, 2, 3]No2 present
54[1, 4, 3]Yes22 next at pos 10, 1 at pos 8, 3 at pos 6. 2’s next is farthest → evict 2
63[1, 4, 3]No3 present
75[1, 5, 3]Yes44 never used again, 1 next at pos 8, 3 at pos 9
81[1, 5, 3]No1 present
93[1, 5, 3]No3 present
102[2, 5, 3]Yes11 never used again; 5 and 3 also no future. Any → evict 1
113[2, 5, 3]No3 present
124[2, 4, 3]Yes5No future for any. Evict 5

OPT faults: 8 (1, 2, 3, 4, 5, 2, 4)

Worked example 2: LRU on the same string

LRU: evict the page whose last use is farthest in the past.

StepRefFrames after (LRU order)Fault?Evicted?
11[1]Yes
22[1, 2]Yes
33[1, 2, 3]Yes
42[1, 3, 2]No
54[3, 2, 4]Yes1 (LRU)
63[2, 4, 3]No
75[4, 3, 5]Yes2 (LRU)
81[3, 5, 1]Yes4 (LRU)
93[5, 1, 3]No
102[1, 3, 2]Yes5 (LRU)
113[1, 2, 3]No
124[2, 3, 4]Yes1 (LRU)

LRU faults: 8 (1, 2, 3, 4, 5, 1, 2, 4). Same as OPT.

Worked example 3: FIFO on the same string

StepRefFrames after (FIFO order)Fault?Evicted?
11[1]Yes
22[1, 2]Yes
33[1, 2, 3]Yes
42[1, 2, 3]No
54[2, 3, 4]Yes1 (oldest)
63[2, 3, 4]No
75[3, 4, 5]Yes2 (oldest)
81[4, 5, 1]Yes3 (oldest)
93[5, 1, 3]Yes4 (oldest)
102[1, 3, 2]Yes5 (oldest)
113[1, 3, 2]No
124[3, 2, 4]Yes1 (oldest)

FIFO faults: 9. Worse than OPT/LRU by 1 fault.

Worked example 4: Belady’s anomaly with FIFO

Reference: 1 2 3 4 1 2 5 1 2 3 4 5

3 frames (FIFO): faults at 1,2,3,4,1,2,5,3,4 = 9 faults. 4 frames (FIFO): faults at 1,2,3,4,1,2,5,1,2,3,4,5 = 10 faults.

More frames → more faults. This is Belady’s anomaly. The extra frame changed the load order so that a useful page (1 or 2) was evicted at a critical moment, causing an extra fault later.

Tripos technique

When answering page-replacement questions:

  1. Draw a table with columns for Step, Reference, Frames (after replacement), Fault? (Yes/No), and optionally Evicted.
  2. Show the frame contents after each reference, not before.
  3. For OPT, compute the “next-use distance” for each resident page after each reference.
  4. For LRU, keep the stack ordered most-to-least recent; the victim is always the last element.
  5. For FIFO, a simple queue suffices — push new pages, pop the oldest.

Past Paper Questions

2024 Paper 2 Question 4(b–c): Compute page-replacement sequences for OPT, LRU, FIFO on 1 2 3 2 4 3 5 1 3 2 3 4 with 3 frames. State and explain Belady’s anomaly. [13 marks]