0
0
Pythonprogramming~5 mins

First Python Program (Hello World) - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: First Python Program (Hello World)
O(1)
Understanding Time Complexity

Let's see how the time it takes to run a simple program changes as we run it.

We want to know how the program's steps grow when we run it.

Scenario Under Consideration

Analyze the time complexity of the following code snippet.

print("Hello, World!")

This code prints a greeting message once.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: A single print statement.
  • How many times: Exactly once.
How Execution Grows With Input

Since the program only prints once, the steps do not grow with input size.

Input Size (n)Approx. Operations
101
1001
10001

Pattern observation: The number of steps stays the same no matter the input size.

Final Time Complexity

Time Complexity: O(1)

This means the program takes the same amount of time no matter what.

Common Mistake

[X] Wrong: "Printing a message depends on input size, so it takes longer with bigger input."

[OK] Correct: The print runs once and does not change with input size, so time stays the same.

Interview Connect

Understanding simple programs helps build a strong base for bigger problems later.

Self-Check

"What if we printed the message inside a loop that runs n times? How would the time complexity change?"