Users and groups in Azure - Time & Space Complexity
When managing users and groups in Azure, it's important to understand how the time to complete tasks grows as you add more users or groups.
We want to know how the number of operations changes when we add more users to groups.
Analyze the time complexity of adding multiple users to a group.
// Add users to a group in Azure AD
foreach (var user in usersList) {
await graphClient.Groups[groupId].Members.References.Request().AddAsync(user);
}
This code adds each user from a list to a single Azure AD group one by one.
Look at what repeats as the list grows:
- Primary operation: API call to add one user to the group.
- How many times: Once for each user in the list.
As you add more users, the number of API calls grows directly with the number of users.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 |
| 100 | 100 |
| 1000 | 1000 |
Pattern observation: Each new user adds exactly one more operation, so the total grows steadily.
Time Complexity: O(n)
This means the time to add users grows in a straight line with the number of users.
[X] Wrong: "Adding multiple users to a group is done in one single API call, so time stays the same no matter how many users."
[OK] Correct: Each user requires a separate API call, so time grows with the number of users.
Understanding how operations scale with input size helps you design efficient cloud solutions and explain your reasoning clearly in interviews.
"What if we batch users and add them in groups of 10 per API call? How would the time complexity change?"