🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Page Replacement Numericals: all 15 questions

Quiz: Page Replacement Numericals · Question 8 of 15

What does this print? (code)

What does this print?

refs = [1, 2, 1, 3, 1, 2]
mem, f = [], 0
for p in refs:
    if p not in mem:
        f += 1
        if len(mem) == 2:
            mem.pop(0)
        mem.append(p)
print(f)
  1. A.3
  2. B.4
  3. C.5
  4. D.6
Answer & explanation

Correct answer: 5

This is FIFO with 2 frames: 1 F, 2 F, 1 hit, 3 F (evict 1), 1 F (evict 2), 2 F (evict 3) → 5 faults.

Can you get the rest right without peeking?

Take the timed Quiz: Page Replacement Numericals quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →