We are given a sequence of 12 page references:
1,3,2,4,2,3,1,2,4,3,1,4 with 3 initially empty frames.
When a page fault occurs, the OS inspects a lookahead window of up to 4 page references (the current page plus the next 3 future page references) and replaces the page in memory that will not be used for the longest time within this 4-page window.
Let's trace step-by-step:
Ref 1: Frame state: {1} → Page Fault (1)
Ref 3: Frame state: {1,3} → Page Fault (2)
Ref 2: Frame state: {1,3,2} → Page Fault (3)
Ref 4: Page fault occurs.
Lookahead window (4 references starting from index 4): ⟨4,2,3,1⟩.
Page 2 is accessed at index 5.
Page 3 is accessed at index 6.
Page 1 is accessed at index 7 (farthest in window).
Therefore, page 1 is replaced with page 4.
Frame state: {4,3,2} → Page Fault (4)
Ref 2: Page 2 is present → Hit (Frames: {4,3,2})
Ref 3: Page 3 is present → Hit (Frames: {4,3,2})
Ref 1: Page fault occurs.
Lookahead window (4 references starting from index 7): ⟨1,2,4,3⟩.
Page 2 is accessed at index 8.
Page 4 is accessed at index 9.
Page 3 is accessed at index 10 (farthest in window).
Therefore, page 3 is replaced with page 1.
Frame state: {4,1,2} → Page Fault (5)
Ref 2: Page 2 is present → Hit (Frames: {4,1,2})
Ref 4: Page 4 is present → Hit (Frames: {4,1,2})
Ref 3: Page fault occurs.
Lookahead window (remaining references starting from index 10): ⟨3,1,4⟩.
Page 1 is accessed at index 11.
Page 4 is accessed at index 12.
Page 2 is not referenced at all within the window.
Therefore, page 2 is replaced with page 3.
Frame state: {4,1,3} → Page Fault (6)
Ref 1: Page 1 is present → Hit (Frames: {4,1,3})
Ref 4: Page 4 is present → Hit (Frames: {4,1,3})
Total number of page faults =6.