0
0
AWScloud~5 mins

Right-sizing resources in AWS - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Right-sizing resources
O(n)
Understanding Time Complexity

When we right-size resources in AWS, we adjust the size or capacity of services to fit the workload.

We want to know how the time to complete this adjustment changes as the number of resources grows.

Scenario Under Consideration

Analyze the time complexity of resizing multiple EC2 instances.


for instance_id in instance_list:
    stop_instance(instance_id)
    modify_instance_type(instance_id, new_type)
    start_instance(instance_id)
    wait_until_running(instance_id)

This sequence stops each instance, changes its type, restarts it, and waits until it is running again.

Identify Repeating Operations

Look at what repeats for each instance.

  • Primary operation: Stopping, modifying, and starting each instance.
  • How many times: Once per instance in the list.
How Execution Grows With Input

Each instance requires the same set of steps, so the total time grows as we add more instances.

Input Size (n)Approx. Api Calls/Operations
10About 10 sets of stop, modify, start, wait
100About 100 sets of stop, modify, start, wait
1000About 1000 sets of stop, modify, start, wait

Pattern observation: The total operations increase directly with the number of instances.

Final Time Complexity

Time Complexity: O(n)

This means the time to right-size grows in direct proportion to how many instances you have.

Common Mistake

[X] Wrong: "Changing the size of many instances takes the same time as changing one."

[OK] Correct: Each instance needs its own stop, modify, and start steps, so more instances mean more total time.

Interview Connect

Understanding how operations scale with resource count helps you plan and explain cloud changes clearly.

Self-Check

"What if we resized instances in parallel instead of one by one? How would the time complexity change?"