Data quality flags in SCADA systems - Time & Space Complexity
We want to understand how the time to check data quality flags changes as we handle more data points.
How does the work grow when we have more sensor readings to check?
Analyze the time complexity of the following code snippet.
for reading in sensor_readings:
if reading.value < 0 or reading.value > reading.max_limit:
reading.flag = 'error'
else:
reading.flag = 'ok'
This code checks each sensor reading and sets a flag based on whether the value is within limits.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Looping through each sensor reading once.
- How many times: Once for every reading in the list.
As the number of readings increases, the time to check flags grows directly with it.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 checks |
| 100 | 100 checks |
| 1000 | 1000 checks |
Pattern observation: Doubling the readings doubles the work needed.
Time Complexity: O(n)
This means the time to set flags grows in a straight line with the number of readings.
[X] Wrong: "Checking flags is always fast and constant time no matter how many readings there are."
[OK] Correct: Each reading must be checked individually, so more readings mean more work.
Understanding how work grows with data size helps you explain system behavior clearly and shows you can think about efficiency in real tasks.
"What if we added nested checks inside the loop for multiple conditions? How would the time complexity change?"
Practice
GOOD data quality flag indicate in a SCADA system?Solution
Step 1: Understand the meaning of data quality flags
Data quality flags classify sensor data status to help users trust or ignore readings.Step 2: Identify the meaning of the GOOD flag
The GOOD flag means the data is reliable and accurate, suitable for use in decisions.Final Answer:
The sensor data is reliable and accurate. -> Option DQuick Check:
GOOD flag = reliable data [OK]
- Confusing GOOD with MISSING or BAD flags
- Assuming GOOD means sensor is offline
- Mixing SUSPECT with GOOD data
Solution
Step 1: Review syntax for string assignment in configuration
Flags are usually strings and must be enclosed in quotes to be valid.Step 2: Identify correct string syntax for BAD flag
Using double quotes around "BAD" is correct; unquoted or lowercase without quotes is invalid.Final Answer:
flag = "BAD" -> Option AQuick Check:
String flags need quotes [OK]
- Omitting quotes around string values
- Using lowercase without quotes
- Confusing variable names with string literals
flags = ["GOOD", "SUSPECT", "BAD", "GOOD", "MISSING"], which flags indicate data that should be excluded from analysis?Solution
Step 1: Identify flags that mark unreliable data
BAD and MISSING flags indicate data that is incorrect or unavailable and should be excluded.Step 2: Match these flags to the options
["BAD", "MISSING"] correctly lists BAD and MISSING as flags to exclude from analysis.Final Answer:
["BAD", "MISSING"] -> Option AQuick Check:
Exclude BAD and MISSING data [OK]
- Including GOOD or SUSPECT data for exclusion
- Confusing SUSPECT as always bad
- Ignoring MISSING data in filtering
filtered = [d for d in data if d.flag != "BAD"]but it still includes some BAD data. What is the likely cause?
Solution
Step 1: Analyze the filtering condition
The condition excludes items where flag equals "BAD" exactly, case-sensitive.Step 2: Identify case sensitivity issue
If some flags are lowercase "bad", they won't match "BAD" and won't be excluded.Final Answer:
The flag comparison is case-sensitive and some flags are lowercase "bad". -> Option CQuick Check:
Case sensitivity causes filtering errors [OK]
- Assuming != excludes all BAD flags regardless of case
- Thinking list comprehension syntax is wrong
- Using wrong comparison operator
BAD or MISSING. Which logical condition correctly implements this?Solution
Step 1: Understand alert condition requirements
The alert should trigger if the flag is BAD or MISSING, meaning either condition is true.Step 2: Choose correct logical operator
Using 'or' checks if flag equals BAD or equals MISSING, which matches the requirement.Final Answer:
if flag == "BAD" or flag == "MISSING": -> Option BQuick Check:
Use 'or' to combine conditions for alert [OK]
- Using 'and' which requires both flags simultaneously
- Using negation incorrectly
- Checking for GOOD or SUSPECT instead
Ready to prove it?
Pass the test and this pattern moves unknown
