0
0
GCPcloud~5 mins

Subnet modes (auto, custom) in GCP - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Subnet modes (auto, custom)
O(n)
Understanding Time Complexity

When creating networks in GCP, subnet modes control how many subnetworks are made automatically or manually.

We want to know how the number of subnetworks affects the work GCP does behind the scenes.

Scenario Under Consideration

Analyze the time complexity of creating subnetworks in different modes.

# Create a network in auto mode
gcloud compute networks create my-auto-network --subnet-mode=auto

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

# Add subnets manually in custom mode
for i in {1..n}; do
  gcloud compute networks subnets create subnet-$i --network=my-custom-network --region=us-central1 --range=10.0.$i.0/24
done

This sequence shows creating a network with automatic subnet creation versus manual subnet creation one by one.

Identify Repeating Operations

Look at what actions happen multiple times.

  • Primary operation: Creating subnetworks (API calls to create subnets)
  • How many times: In auto mode, subnets are created once automatically for each region; in custom mode, each subnet creation is a separate call repeated n times.
How Execution Grows With Input

As the number of subnetworks (n) increases, the number of subnet creation calls grows.

Input Size (n)Approx. API Calls/Operations
1010 subnet creation calls in custom mode; 1 in auto mode
100100 subnet creation calls in custom mode; 1 in auto mode
10001000 subnet creation calls in custom mode; 1 in auto mode

Pattern observation: Custom mode scales linearly with the number of subnets; auto mode does not increase calls with subnet count.

Final Time Complexity

Time Complexity: O(n)

This means the work grows directly with how many subnets you create manually in custom mode.

Common Mistake

[X] Wrong: "Creating many subnets in custom mode is as fast as auto mode because GCP handles it."

[OK] Correct: Each subnet creation is a separate action, so more subnets mean more work and time.

Interview Connect

Understanding how resource creation scales helps you design efficient cloud networks and explain your choices clearly.

Self-Check

"What if we batch subnet creations in custom mode using scripts or APIs? How would the time complexity change?"