Why cybersecurity matters - Performance Analysis
We want to understand how the effort to protect systems grows as threats increase.
How does the work needed to keep data safe change when more attacks happen?
Analyze the time complexity of the following code snippet.
for attack in detected_attacks:
analyze(attack)
if attack.is_severe():
alert_team(attack)
log_attack(attack)
This code checks each detected attack, analyzes it, alerts the team if severe, and logs it.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Looping through each detected attack.
- How many times: Once for every attack found.
As the number of attacks grows, the work grows in the same way.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | About 10 checks and actions |
| 100 | About 100 checks and actions |
| 1000 | About 1000 checks and actions |
Pattern observation: The work grows steadily as attacks increase, doubling attacks roughly doubles work.
Time Complexity: O(n)
This means the time to handle attacks grows directly with how many attacks there are.
[X] Wrong: "Handling more attacks takes the same time as handling one."
[OK] Correct: Each attack needs separate checking and action, so more attacks mean more work.
Understanding how work grows with threats helps you explain how to design systems that stay efficient and safe as risks increase.
"What if the code also checked every attack against a list of known patterns? How would the time complexity change?"