Azure Advisor recommendations - Time & Space Complexity
We want to understand how the time to get Azure Advisor recommendations changes as we ask for more resources.
Specifically, how does the number of resources affect the work Azure Advisor does?
Analyze the time complexity of the following operation sequence.
// Get recommendations for a subscription
var recommendations = await advisorClient.Recommendations.ListAsync(subscriptionId);
// For each recommendation, get detailed metadata
foreach (var rec in recommendations.Value)
{
var details = await advisorClient.Recommendations.GetAsync(subscriptionId, rec.Name);
}
This code fetches all recommendations for a subscription, then fetches details for each recommendation.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Calling the API to get details for each recommendation.
- How many times: Once for each recommendation returned in the list.
As the number of recommendations grows, the number of detail calls grows the same way.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 1 list call + 10 detail calls = 11 calls |
| 100 | 1 list call + 100 detail calls = 101 calls |
| 1000 | 1 list call + 1000 detail calls = 1001 calls |
Pattern observation: The total calls grow roughly in direct proportion to the number of recommendations.
Time Complexity: O(n)
This means the time to get all details grows linearly as the number of recommendations increases.
[X] Wrong: "Getting all recommendations and their details takes the same time no matter how many recommendations there are."
[OK] Correct: Each recommendation requires a separate detail call, so more recommendations mean more calls and more time.
Understanding how API calls scale with input size helps you design efficient cloud solutions and explain performance in real projects.
"What if the API allowed fetching details for all recommendations in a single call? How would the time complexity change?"