Trend charts and historical data in SCADA systems - Time & Space Complexity
When working with trend charts and historical data in SCADA systems, it is important to understand how the time to process data grows as more data points are added.
We want to know how the system's work changes when the amount of stored data increases.
Analyze the time complexity of the following code snippet.
// Retrieve and process historical data for trend chart
function generateTrendChart(dataPoints) {
for (let i = 0; i < dataPoints.length; i++) {
processData(dataPoints[i]);
}
renderChart();
}
// processData handles one data point
// renderChart draws the chart after processing
This code loops through all stored data points to prepare them for the trend chart, then renders the chart once.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Loop over all data points to process each one.
- How many times: Exactly once per data point, so as many times as there are data points.
As the number of data points increases, the time to process them grows in a straight line.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 processing steps |
| 100 | 100 processing steps |
| 1000 | 1000 processing steps |
Pattern observation: Doubling the data points roughly doubles the work needed.
Time Complexity: O(n)
This means the time to prepare the trend chart grows directly with the number of data points.
[X] Wrong: "Processing historical data takes the same time no matter how many points there are."
[OK] Correct: Each data point must be handled, so more points mean more work and more time.
Understanding how data size affects processing time is a key skill for working with SCADA systems and real-time monitoring tools.
What if we cached processed data points instead of processing all every time? How would the time complexity change?