0
0
Computer Networksknowledge~5 mins

HTTP and HTTPS in Computer Networks - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: HTTP and HTTPS
O(n)
Understanding Time Complexity

When we use HTTP or HTTPS, our devices send and receive data over the internet. Understanding how the time it takes to complete these exchanges grows as the amount of data or number of requests increases helps us see how fast or slow web communication can be.

We want to know: How does the time to load a webpage or send data change when more information or more users are involved?

Scenario Under Consideration

Analyze the time complexity of the following simplified HTTP request process.


function sendHttpRequest(url, isHttps) {
  establishConnection(url);       // Open connection to server
  if (isHttps) {
    performTlsHandshake();        // Secure connection setup
  }
  sendRequestHeaders();           // Send headers
  receiveResponse();              // Get data from server
  closeConnection();              // Close connection
}
    

This code shows the steps a device takes to send an HTTP or HTTPS request and get a response.

Identify Repeating Operations

Look for parts that repeat or take time depending on input size.

  • Primary operation: Receiving the response data from the server.
  • How many times: This depends on the size of the data sent back; larger data means more time receiving.
How Execution Grows With Input

As the amount of data from the server grows, the time to receive it grows roughly in direct proportion.

Input Size (data in KB)Approx. Operations (time units)
1010 units
100100 units
10001000 units

Pattern observation: The time to receive data grows linearly with the size of the data. More data means more time.

Final Time Complexity

Time Complexity: O(n)

This means the time to complete the request grows in direct proportion to the amount of data received.

Common Mistake

[X] Wrong: "HTTPS always takes twice as long as HTTP because of encryption overhead."

[OK] Correct: While HTTPS adds extra steps for security, the main time depends on data size. For small data, the difference is small; for large data, receiving data dominates time.

Interview Connect

Understanding how data size affects request time helps you explain real-world web performance. This skill shows you can think about how network steps impact user experience.

Self-Check

"What if the connection used HTTP/2 with multiplexing? How would the time complexity change when sending multiple requests?"