Risk analysis (probability and impact) in Software Engineering - Time & Space Complexity
When analyzing risk, we want to understand how likely a problem is and how big its effect could be.
We ask: How does the chance and impact of risks grow as we consider more factors?
Analyze the time complexity of the following risk scoring process.
risks = [ ... ] # list of risk items
for risk in risks:
probability = risk.getProbability()
impact = risk.getImpact()
riskScore = probability * impact
recordRiskScore(risk, riskScore)
This code calculates a risk score for each risk by multiplying its probability and impact.
Look for repeated actions that take time.
- Primary operation: Looping through each risk item once.
- How many times: Once per risk, so as many times as there are risks.
As the number of risks increases, the work grows in a simple way.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 calculations |
| 100 | 100 calculations |
| 1000 | 1000 calculations |
Pattern observation: The work grows directly with the number of risks.
Time Complexity: O(n)
This means the time to calculate risk scores grows in a straight line as the number of risks grows.
[X] Wrong: "Calculating risk scores takes the same time no matter how many risks there are."
[OK] Correct: Each risk needs its own calculation, so more risks mean more work.
Understanding how risk calculations scale helps you explain how your code handles growing data clearly and confidently.
"What if we had to compare every risk with every other risk? How would the time complexity change?"
Practice
Solution
Step 1: Understand risk analysis components
Risk analysis involves assessing how likely a problem is and how severe its consequences could be.Step 2: Identify what is combined
The two main factors combined are probability (likelihood) and impact (severity).Final Answer:
The likelihood of a problem and its potential impact -> Option DQuick Check:
Risk = Probability x Impact [OK]
- Confusing risk with project cost
- Mixing team size with risk factors
- Thinking risk depends on programming language
Solution
Step 1: Recall risk score calculation
The risk score is calculated by multiplying the probability of an event by its impact.Step 2: Evaluate each formula
Addition, subtraction, or division do not correctly represent risk score calculation.Final Answer:
Risk score = Probability x Impact -> Option CQuick Check:
Risk score uses multiplication [OK]
- Adding probability and impact instead of multiplying
- Dividing impact by probability
- Subtracting values instead of combining
Solution
Step 1: Identify given values
Probability = 0.3, Impact = 8.Step 2: Calculate risk score by multiplying
Risk score = 0.3 x 8 = 2.4.Final Answer:
2.4 -> Option BQuick Check:
0.3 x 8 = 2.4 [OK]
- Adding instead of multiplying
- Multiplying in reverse order but miscalculating
- Confusing decimal multiplication
Solution
Step 1: Identify the calculation mistake
The manager added probability and impact instead of multiplying them.Step 2: Understand correct risk score formula
Risk score must be calculated by multiplying probability and impact to reflect combined effect.Final Answer:
Using addition instead of multiplication for risk score -> Option AQuick Check:
Risk score = Probability x Impact, not addition [OK]
- Adding values instead of multiplying
- Forgetting to include impact
- Misinterpreting probability scale
Solution
Step 1: Calculate risk scores for each risk
Risk A: 0.2 x 10 = 2.0
Risk B: 0.5 x 3 = 1.5
Risk C: 0.1 x 15 = 1.5Step 2: Compare risk scores to prioritize
Risk A has the highest score of 2.0.Final Answer:
Risk A -> Option AQuick Check:
Risk A score = 2.0 > others [OK]
- Choosing risk with highest probability only
- Choosing risk with highest impact only
- Assuming all risks have equal priority
Ready to prove it?
Pass the test and this pattern moves unknown
