Receiving telemetry data in Drone Programming - Time & Space Complexity
When receiving telemetry data, it's important to know how the time to process data changes as more data arrives.
We want to understand how the program's work grows as the amount of telemetry data increases.
Analyze the time complexity of the following code snippet.
function receiveTelemetry(dataPackets) {
for (const packet of dataPackets) {
process(packet);
}
}
function process(packet) {
// process single telemetry packet
}
This code receives a list of telemetry data packets and processes each one in order.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Looping through each telemetry packet in the dataPackets list.
- How many times: Once for each packet in the input list.
As the number of telemetry packets increases, the time to process them grows in a straight line.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 loops and 10 process calls |
| 100 | 100 loops and 100 process calls |
| 1000 | 1000 loops and 1000 process calls |
Pattern observation: Doubling the input doubles the work done.
Time Complexity: O(n)
This means the time to receive and process telemetry data grows directly with the number of packets.
[X] Wrong: "Processing one packet takes constant time, so the whole function is always fast regardless of input size."
[OK] Correct: Even if one packet is quick, processing many packets adds up, so total time grows with the number of packets.
Understanding how processing time grows with data size is a key skill for working with real-time drone telemetry and similar data streams.
"What if the process function itself loops over a fixed-size array inside each packet? How would the time complexity change?"