Azure Savings Plans - Time & Space 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?
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 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.
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 |
|---|---|
| 10 | About 10 x number of savings plans |
| 100 | About 100 x number of savings plans |
| 1000 | About 1000 x number of savings plans |
Pattern observation: The total operations grow roughly in direct proportion to the number of resources.
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.
[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.
Understanding how operations scale with resource count helps you design efficient cloud cost management solutions.
"What if we cached the matching savings plan for each resource type? How would the time complexity change?"