← 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))
- A.3
- B.4
- C.5
- 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 →