Remote start/stop operations in SCADA systems - Time & Space Complexity
When controlling machines remotely, it is important to know how the time to process commands changes as more devices are involved.
We want to understand how the system handles starting or stopping many devices and how the time grows.
Analyze the time complexity of the following code snippet.
// Remote start all devices
for device in devices:
if device.status == 'stopped':
device.send_command('start')
device.status = 'running'
This code loops through all devices and starts each one if it is stopped.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Looping through each device in the list.
- How many times: Once for every device in the system.
As the number of devices increases, the time to send start commands grows proportionally.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 checks and possible commands |
| 100 | 100 checks and possible commands |
| 1000 | 1000 checks and possible commands |
Pattern observation: The operations increase directly with the number of devices.
Time Complexity: O(n)
This means the time to start devices grows in a straight line as more devices are added.
[X] Wrong: "Starting multiple devices happens instantly no matter how many there are."
[OK] Correct: Each device needs a command sent, so more devices mean more work and more time.
Understanding how command processing time grows helps you design systems that scale well and stay responsive.
"What if we could send commands to all devices at once instead of one by one? How would the time complexity change?"