0
0
AWScloud~5 mins

Performance efficiency pillar in AWS - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Performance efficiency pillar
O(n)
Understanding Time Complexity

We want to understand how the time to perform cloud tasks changes as we add more resources or users.

How does the system keep up when demand grows?

Scenario Under Consideration

Analyze the time complexity of the following operation sequence.


// Create multiple EC2 instances
for (let i = 0; i < n; i++) {
  ec2.runInstances({
    ImageId: 'ami-12345678',
    InstanceType: 't3.micro',
    MinCount: 1,
    MaxCount: 1
  }).promise();
}
    

This sequence launches n EC2 instances one by one to handle increased workload.

Identify Repeating Operations

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

  • Primary operation: EC2 runInstances API call to launch one instance
  • How many times: n times, once per instance
How Execution Grows With Input

Each new instance requires a separate API call and provisioning time.

Input Size (n)Approx. Api Calls/Operations
1010 EC2 runInstances calls
100100 EC2 runInstances calls
10001000 EC2 runInstances calls

Pattern observation: The number of operations grows directly with the number of instances requested.

Final Time Complexity

Time Complexity: O(n)

This means the time to launch instances grows in direct proportion to how many you want.

Common Mistake

[X] Wrong: "Launching more instances happens instantly and does not add time."

[OK] Correct: Each instance requires a separate API call and setup time, so more instances mean more total time.

Interview Connect

Understanding how cloud operations scale helps you design systems that stay fast as they grow.

Self-Check

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