TCP connection termination (four-way handshake) in Computer Networks - Time & Space Complexity
When closing a TCP connection, the four-way handshake ensures both sides agree to end communication safely.
We want to understand how the number of steps grows as the connection closes.
Analyze the time complexity of the TCP four-way handshake termination process.
1. Host A sends FIN to Host B
2. Host B sends ACK to Host A
3. Host B sends FIN to Host A
4. Host A sends ACK to Host B
This sequence shows the four messages exchanged to close a TCP connection properly.
Look for repeated actions or message exchanges.
- Primary operation: Sending and receiving control messages (FIN and ACK packets)
- How many times: Exactly four message exchanges happen, each once per connection termination
The number of messages to close a connection stays the same no matter how long the connection was open.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 connections | 40 messages (4 per connection) |
| 100 connections | 400 messages |
| 1000 connections | 4000 messages |
Pattern observation: The total messages grow linearly with the number of connections, but each connection always uses four messages.
Time Complexity: O(1)
This means closing one TCP connection always takes a fixed number of steps, regardless of connection length.
[X] Wrong: "The termination time depends on how much data was sent during the connection."
[OK] Correct: The four-way handshake only handles closing the connection, not the data transfer, so its steps stay constant.
Understanding fixed-step processes like TCP termination helps you explain how protocols manage communication efficiently and predictably.
"What if the TCP connection used a three-way handshake to close instead of four steps? How would that affect the time complexity?"