Edge gateway architecture in IOT Protocols - Time & Space Complexity
We want to understand how the work done by an edge gateway grows as it processes more devices or messages.
How does the time to handle data increase when more sensors connect to the gateway?
Analyze the time complexity of the following code snippet.
function processMessages(devices) {
for (let device of devices) {
let messages = device.getMessages();
for (let msg of messages) {
processMessage(msg);
}
}
}
This code processes messages from multiple devices connected to the edge gateway.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Nested loops over devices and their messages.
- How many times: Outer loop runs once per device; inner loop runs once per message per device.
As the number of devices and messages per device increase, the total work grows by multiplying these counts.
| Input Size (devices x messages) | Approx. Operations |
|---|---|
| 10 devices x 5 messages | 50 |
| 100 devices x 5 messages | 500 |
| 100 devices x 100 messages | 10,000 |
Pattern observation: The total operations grow proportionally to the number of devices times the number of messages per device.
Time Complexity: O(d * m)
This means the time grows in proportion to the number of devices times the messages each device sends.
[X] Wrong: "The time grows only with the number of devices, ignoring messages."
[OK] Correct: Each device can send many messages, so total work depends on both devices and messages.
Understanding how nested loops affect processing time helps you explain system performance clearly and confidently.
What if the gateway batches messages from all devices before processing? How would the time complexity change?