Subnets within a VNet in Azure - Time & Space Complexity
When creating subnets inside a virtual network, it is important to understand how the time to set up grows as you add more subnets.
We want to know how the number of subnets affects the total time and operations needed.
Analyze the time complexity of the following operation sequence.
# Create a virtual network
az network vnet create --name MyVNet --resource-group MyResourceGroup --address-prefix 10.0.0.0/16
# Create multiple subnets inside the VNet
for i in $(seq 1 5); do
az network vnet subnet create --resource-group MyResourceGroup --vnet-name MyVNet --name Subnet$i --address-prefix 10.0.$i.0/24
done
This sequence creates one virtual network and then adds several subnets inside it, each with its own address range.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Creating each subnet inside the virtual network.
- How many times: Once for the virtual network, then once per subnet (e.g., 5 times in the example).
Each subnet creation requires a separate API call, so the total operations grow as you add more subnets.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 1 (VNet) + 10 (subnets) = 11 |
| 100 | 1 + 100 = 101 |
| 1000 | 1 + 1000 = 1001 |
Pattern observation: The total operations increase linearly as the number of subnets increases.
Time Complexity: O(n)
This means the time to create subnets grows directly in proportion to how many subnets you add.
[X] Wrong: "Creating multiple subnets happens all at once, so time stays the same no matter how many subnets."
[OK] Correct: Each subnet creation is a separate call and takes time, so adding more subnets adds more work.
Understanding how resource creation scales helps you design efficient cloud setups and explain your reasoning clearly in interviews.
"What if we created subnets in parallel instead of one after another? How would the time complexity change?"