Compliance reporting in SCADA systems - Time & Space Complexity
When generating compliance reports in SCADA systems, it is important to understand how the time to create these reports changes as the amount of data grows.
We want to know how the system's work increases when more data points or events are included in the report.
Analyze the time complexity of the following code snippet.
function generateComplianceReport(dataPoints) {
let report = []
for (let i = 0; i < dataPoints.length; i++) {
if (dataPoints[i].status === 'non-compliant') {
report.push(dataPoints[i])
}
}
return report
}
This code goes through all data points and collects those that are marked as non-compliant to create a report.
- Primary operation: A single loop that checks each data point once.
- How many times: The loop runs once for every data point in the input list.
As the number of data points increases, the time to generate the report grows in a straight line.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 checks |
| 100 | 100 checks |
| 1000 | 1000 checks |
Pattern observation: Doubling the data points roughly doubles the work done.
Time Complexity: O(n)
This means the time to create the report grows directly with the number of data points.
[X] Wrong: "The report generation time stays the same no matter how many data points there are."
[OK] Correct: The code checks each data point once, so more data means more checks and more time.
Understanding how report generation time grows helps you explain system behavior clearly and shows you can think about scaling in real projects.
"What if the code also sorted the collected non-compliant data points before returning? How would the time complexity change?"