Real-time data display in SCADA systems - Time & Space Complexity
When showing real-time data in SCADA systems, it's important to know how the system handles updates as data grows.
We want to understand how the time to update the display changes when more data points come in.
Analyze the time complexity of the following code snippet.
function updateDisplay(dataPoints) {
for (let i = 0; i < dataPoints.length; i++) {
display.update(dataPoints[i]);
}
}
// dataPoints is an array of sensor readings
// display.update shows each reading on the screen
This code updates the display by going through each data point and showing it one by one.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Looping through each data point to update the display.
- How many times: Once for every data point in the input array.
As the number of data points increases, the time to update grows in a straight line.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 updates |
| 100 | 100 updates |
| 1000 | 1000 updates |
Pattern observation: Doubling the data points doubles the work needed to update the display.
Time Complexity: O(n)
This means the time to update grows directly with the number of data points.
[X] Wrong: "Updating the display takes the same time no matter how many data points there are."
[OK] Correct: Each data point needs its own update, so more points mean more work and more time.
Understanding how update time grows with data size helps you design systems that stay fast and responsive as they handle more information.
"What if the display updated only changed data points instead of all points? How would the time complexity change?"