🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Virtual Memory: all 10 questions

Quiz: Virtual Memory · Question 8 of 10

What does this print? (code)

What does this print?

def fifo_faults(ref, frames):
    mem, faults = [], 0
    for p in ref:
        if p not in mem:
            faults += 1
            if len(mem) == frames:
                mem.pop(0)
            mem.append(p)
    return faults

print(fifo_faults([1, 2, 3, 1, 4, 2], 3))
  1. A.3
  2. B.4
  3. C.5
  4. D.6
Answer & explanation

Correct answer: 4

1, 2, 3 fault; 1 hits; 4 replaces 1 (the oldest); 2 is still in memory and hits. Total 4.

Can you get the rest right without peeking?

Take the timed Quiz: Virtual Memory quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →