0
0
Azurecloud~5 mins

Azure Savings Plans - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Azure Savings Plans
O(n * m)
Understanding Time Complexity

We want to understand how the time to calculate and apply Azure Savings Plans changes as the number of resources grows.

How does the system handle more resources when applying savings plans?

Scenario Under Consideration

Analyze the time complexity of the following operation sequence.


// Pseudocode for applying Azure Savings Plans
var resources = GetAllResources();
var savingsPlans = GetActiveSavingsPlans();

foreach (var resource in resources) {
  foreach (var plan in savingsPlans) {
    if (plan.AppliesTo(resource)) {
      ApplyDiscount(resource, plan);
      break;
    }
  }
}
    

This sequence checks each resource against active savings plans and applies the first matching discount.

Identify Repeating Operations

Identify the API calls, resource provisioning, data transfers that repeat.

  • Primary operation: Checking each resource against each savings plan to find a match.
  • How many times: For every resource, the system may check multiple savings plans until one applies.
How Execution Grows With Input

As the number of resources grows, the number of checks grows too, since each resource is compared to savings plans.

Input Size (n resources)Approx. Api Calls/Operations
10About 10 x number of savings plans
100About 100 x number of savings plans
1000About 1000 x number of savings plans

Pattern observation: The total operations grow roughly in direct proportion to the number of resources.

Final Time Complexity

Time Complexity: O(n * m)

This means the time to apply savings plans grows linearly with the number of resources and the number of savings plans.

Common Mistake

[X] Wrong: "Applying savings plans takes the same time no matter how many resources there are."

[OK] Correct: Each resource must be checked, so more resources mean more work and more time.

Interview Connect

Understanding how operations scale with resource count helps you design efficient cloud cost management solutions.

Self-Check

"What if we cached the matching savings plan for each resource type? How would the time complexity change?"