0
0
GCPcloud~5 mins

Custom VPC creation in GCP - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Custom VPC creation
O(n + m)
Understanding Time Complexity

When creating a custom Virtual Private Cloud (VPC) in GCP, it is important to understand how the time to complete the setup changes as you add more components.

We want to know how the number of steps or API calls grows when we create more subnets or firewall rules.

Scenario Under Consideration

Analyze the time complexity of the following operation sequence.

# Create a custom VPC network
gcloud compute networks create my-vpc --subnet-mode=custom

# Create multiple subnets in the VPC
for i in $(seq 1 n); do
  gcloud compute networks subnets create subnet-$i --network=my-vpc --region=region-$i --range=10.$i.0.0/24
done

# Create firewall rules for the VPC
for i in $(seq 1 m); do
  gcloud compute firewall-rules create fw-rule-$i --network=my-vpc --allow tcp:80
done

This sequence creates a custom VPC, then adds multiple subnets and firewall rules to it.

Identify Repeating Operations

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

  • Primary operation: Creating subnets and firewall rules via API calls.
  • How many times: Subnet creation happens n times; firewall rule creation happens m times.
How Execution Grows With Input

Each subnet and firewall rule requires a separate API call, so the total number of calls grows as you add more.

Input Size (n + m)Approx. Api Calls/Operations
10About 10 calls (e.g., 5 subnets + 5 firewall rules)
100About 100 calls (e.g., 50 subnets + 50 firewall rules)
1000About 1000 calls (e.g., 500 subnets + 500 firewall rules)

Pattern observation: The total work grows directly with the number of subnets and firewall rules you create.

Final Time Complexity

Time Complexity: O(n + m)

This means the time to create the VPC setup grows linearly with the number of subnets and firewall rules added.

Common Mistake

[X] Wrong: "Creating one big VPC network means all subnets and rules are created instantly in one step."

[OK] Correct: Each subnet and firewall rule requires its own API call and setup time, so the total time grows with how many you add.

Interview Connect

Understanding how the number of resources affects setup time helps you plan and explain cloud infrastructure tasks clearly and confidently.

Self-Check

"What if we created all subnets in parallel instead of one after another? How would the time complexity change?"