Time Complexity & Big-O
DSA · Beginner
Definition
Big-O describes how the running time or memory of an algorithm grows as input size grows.
Lets you compare solutions and predict whether code will pass limits.
Diagram
Flowchart
Example: Nested loop is O(n²)
n = 4
count = 0
for i in range(n):
for j in range(n):
count += 1
print(count)Output: 16
Key points
- ~10⁸ simple operations per second is a rough guide
- Halving the input each step gives log n
Interview questions
Is O(2n) different from O(n)?
No, constants are dropped; both are O(n).