0
0
Computer Networksknowledge~5 mins

Three-way handshake in Computer Networks - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Three-way handshake
O(n)
Understanding Time Complexity

When devices start a connection using the three-way handshake, it is important to understand how the steps grow as more connections happen.

We want to know how the time to complete the handshake changes when many devices try to connect.

Scenario Under Consideration

Analyze the time complexity of the following handshake process.


// Simplified three-way handshake steps
send SYN to server
wait for SYN-ACK from server
send ACK to server
connection established
    

This code shows the three main message exchanges to start a connection between two devices.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: Sending and receiving three messages in sequence.
  • How many times: Exactly three message exchanges per connection.
How Execution Grows With Input

Each connection requires three messages. If we have more connections, the total messages grow proportionally.

Input Size (number of connections)Approx. Messages Sent
1030
100300
10003000

Pattern observation: The total messages increase directly with the number of connections.

Final Time Complexity

Time Complexity: O(n)

This means the time to complete handshakes grows linearly as more connections start.

Common Mistake

[X] Wrong: "The handshake time grows faster than the number of connections because of waiting times stacking up."

[OK] Correct: Each handshake happens independently and requires a fixed number of steps, so total time grows directly with connections, not faster.

Interview Connect

Understanding how connection setup time scales helps you explain network performance clearly and confidently in real-world discussions.

Self-Check

What if the handshake required an extra message for security checks? How would the time complexity change?