0
0
Computer Networksknowledge~5 mins

Flow control (stop-and-wait, sliding window) in Computer Networks - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Flow control (stop-and-wait, sliding window)
O(n)
Understanding Time Complexity

When sending data over a network, flow control methods decide how fast data moves between sender and receiver.

We want to understand how the time to send many packets grows as the number of packets increases.

Scenario Under Consideration

Analyze the time complexity of sending packets using stop-and-wait and sliding window flow control.


// Stop-and-Wait flow control
for each packet in total_packets:
    send(packet)
    wait for acknowledgment

// Sliding Window flow control
window_size = W
while packets remain:
    send up to W packets without waiting
    wait for acknowledgments of sent packets
    slide window forward

This code shows two ways to send packets: one waits after each packet, the other sends many before waiting.

Identify Repeating Operations

Look at what repeats as we send packets.

  • Primary operation: Sending packets and waiting for acknowledgments.
  • How many times: Stop-and-wait waits after each packet, so it repeats send-and-wait for every packet. Sliding window sends multiple packets before waiting, repeating send-and-wait fewer times.
How Execution Grows With Input

As the number of packets grows, the total time to send them changes differently for each method.

Input Size (n)Stop-and-Wait Approx. OperationsSliding Window Approx. Operations
1010 send-wait cyclesAbout 2-3 send-wait cycles (if window size ~4-5)
100100 send-wait cyclesAbout 20-25 send-wait cycles
10001000 send-wait cyclesAbout 200-250 send-wait cycles

Pattern observation: Stop-and-wait grows linearly with packets. Sliding window reduces waiting by grouping packets, so it grows slower in practice.

Final Time Complexity

Time Complexity: O(n)

This means the total time to send packets grows roughly in direct proportion to the number of packets, but sliding window reduces waiting overhead.

Common Mistake

[X] Wrong: "Sliding window always sends packets instantly with no waiting, so it has zero delay regardless of packet count."

[OK] Correct: Even sliding window must wait for acknowledgments after sending a group of packets, so waiting still grows with total packets, just less often.

Interview Connect

Understanding how flow control affects sending time helps you explain network efficiency and design better communication protocols.

Self-Check

What if we increased the sliding window size to cover all packets at once? How would the time complexity change?