0
0
Computer Networksknowledge~5 mins

Why UDP is faster than TCP in Computer Networks - Performance Analysis

Choose your learning style9 modes available
Time Complexity: Why UDP is faster than TCP
O(n)
Understanding Time Complexity

We want to understand why UDP generally works faster than TCP in computer networks.

Specifically, how the steps each protocol takes affect the time it takes to send data.

Scenario Under Consideration

Analyze the time complexity of the following simplified protocol steps.


// TCP sending data
establishConnection()
while (dataToSend) {
  sendPacket()
  waitForAck()
}
closeConnection()

// UDP sending data
while (dataToSend) {
  sendPacket()
}

This code shows TCP needing extra steps like connection setup and waiting for acknowledgments, while UDP just sends packets without waiting.

Identify Repeating Operations

Look at what repeats as data size grows.

  • Primary operation: Sending packets repeatedly for each piece of data.
  • How many times: Once per data packet, proportional to data size.
  • TCP also repeats waiting for acknowledgments after each packet, adding extra steps.
How Execution Grows With Input

As the amount of data grows, the number of packets sent grows the same way.

Input Size (n packets)Approx. Operations TCPApprox. Operations UDP
10~30 (includes setup, send, ack, close)~10 (just send)
100~300~100
1000~3000~1000

Pattern observation: TCP does roughly three times more operations than UDP for the same data size because of extra steps.

Final Time Complexity

Time Complexity: O(n)

This means both protocols take time proportional to the amount of data, but TCP has more steps per data unit, making it slower.

Common Mistake

[X] Wrong: "UDP is faster because it sends fewer packets than TCP."

[OK] Correct: Both send the same number of packets for the same data; UDP is faster because it skips extra steps like connection setup and acknowledgments.

Interview Connect

Understanding how protocols handle data helps you explain network performance clearly and shows you can think about efficiency in real systems.

Self-Check

"What if TCP did not wait for acknowledgments after each packet? How would that affect its time complexity compared to UDP?"