0
0
Software Engineeringknowledge~5 mins

Risk analysis (probability and impact) in Software Engineering - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Risk analysis (probability and impact)
O(n)
Understanding Time 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?

Scenario Under Consideration

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.

Identify Repeating Operations

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.
How Execution Grows With Input

As the number of risks increases, the work grows in a simple way.

Input Size (n)Approx. Operations
1010 calculations
100100 calculations
10001000 calculations

Pattern observation: The work grows directly with the number of risks.

Final Time Complexity

Time Complexity: O(n)

This means the time to calculate risk scores grows in a straight line as the number of risks grows.

Common Mistake

[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.

Interview Connect

Understanding how risk calculations scale helps you explain how your code handles growing data clearly and confidently.

Self-Check

"What if we had to compare every risk with every other risk? How would the time complexity change?"