🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Flow Control and Sliding Window: all 10 questions

Quiz: Flow Control and Sliding Window · Question 9 of 10

What does this print? (code)

What does this print?

def gbn_transmissions(n_frames, window, lost):
    sends, base, lost = [], 0, sorted(lost)
    while base < n_frames:
        nxt = next((f for f in lost if f >= base), None)
        last = n_frames - 1 if nxt is None else min(nxt + window - 1, n_frames - 1)
        sends += list(range(base, last + 1))
        if nxt is None:
            break
        lost.remove(nxt)
        base = nxt
    return sends

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

Correct answer: 8

First round: frames 0 to 3 (the window of 3 starting at lost frame 1 ends at 3) — 4 sends. Then the sender goes back to 1 and sends 1 to 4 — 4 more. Total 8.

Can you get the rest right without peeking?

Take the timed Quiz: Flow Control and Sliding Window quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →