0
0
Arduinoprogramming~5 mins

HTTP requests from Arduino - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: HTTP requests from Arduino
O(n)
Understanding Time Complexity

When an Arduino sends HTTP requests, it performs steps repeatedly to communicate with a server.

We want to understand how the time it takes grows as the number of requests increases.

Scenario Under Consideration

Analyze the time complexity of the following code snippet.


#include <WiFi.h>
#include <HTTPClient.h>

void sendRequests(int n) {
  for (int i = 0; i < n; i++) {
    HTTPClient http;
    http.begin("http://example.com/data");
    int code = http.GET();
    http.end();
  }
}
    

This code sends n HTTP GET requests one after another to a server.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: Sending an HTTP GET request inside the loop.
  • How many times: Exactly n times, once per loop iteration.
How Execution Grows With Input

Each request takes roughly the same time, so total time grows as we send more requests.

Input Size (n)Approx. Operations
1010 HTTP requests
100100 HTTP requests
10001000 HTTP requests

Pattern observation: The total time grows directly in proportion to the number of requests.

Final Time Complexity

Time Complexity: O(n)

This means if you double the number of requests, the total time roughly doubles too.

Common Mistake

[X] Wrong: "Sending multiple HTTP requests happens all at once, so time stays the same no matter how many requests."

[OK] Correct: Each request waits for a response before the next starts, so time adds up with each request.

Interview Connect

Understanding how repeated network calls affect time helps you design better programs and explain your choices clearly.

Self-Check

"What if we sent all HTTP requests at the same time using asynchronous calls? How would the time complexity change?"