0
0
GCPcloud~5 mins

Boot disk images in GCP - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Boot disk images
O(n)
Understanding Time Complexity

When creating virtual machines, boot disk images are copied to start the machine. Understanding how the time to create these machines grows helps us plan better.

We want to know: how does the time to create multiple VMs with boot disk images grow as we add more machines?

Scenario Under Consideration

Analyze the time complexity of creating multiple VMs each with a boot disk image.

for i in range(n):
    compute.instances().insert(
        project=project_id,
        zone=zone,
        body={
            'name': f'vm-{i}',
            'disks': [{
                'boot': True,
                'initializeParams': {'sourceImage': image_url}
            }],
            'machineType': machine_type
        }
    ).execute()

This code creates n virtual machines, each with a boot disk initialized from the same image.

Identify Repeating Operations

Look at what repeats as we create more VMs.

  • Primary operation: API call to create a VM with a boot disk image.
  • How many times: Once per VM, so n times.
How Execution Grows With Input

Each VM creation requires copying the boot disk image once. So, if you create more VMs, the total work grows directly with the number of VMs.

Input Size (n)Approx. API Calls/Operations
1010 VM creation calls
100100 VM creation calls
10001000 VM creation calls

Pattern observation: The number of operations grows in a straight line as you add more VMs.

Final Time Complexity

Time Complexity: O(n)

This means the time to create VMs grows directly with how many you want to create.

Common Mistake

[X] Wrong: "Creating multiple VMs with the same boot image happens instantly after the first one."

[OK] Correct: Each VM needs its own boot disk copy, so the work repeats for each VM, not just once.

Interview Connect

Understanding how resource creation scales helps you design systems that grow smoothly. This skill shows you can think about costs and delays as systems get bigger.

Self-Check

"What if we used a shared persistent disk instead of separate boot disks? How would the time complexity change?"