What Is Big-O?
Big-O: lesson 1 of 5
Stop timing code. Start predicting how it scales.
Lesson 1 of 5 · 4 min
What Is Big-O?
Step 1 of 7
n—
Big-O plots work against input size — never seconds, never hardware.
The Idea
Big-O describes how an algorithm's work grows as its input grows. It deliberately ignores hardware, language, and constant factors. What's left is the shape of the growth curve, and that shape is the only thing that survives when data gets big.
Real-World Example
Airport security is a fair comparison. Adding one more traveller barely changes the wait, but doubling the crowd roughly doubles it. The number on the clock matters far less than that relationship.
The Code
def total(nums):
# one pass over n items -> work grows with n
s = 0
for x in nums: # runs n times
s += x
return s
# n = 10 -> 10 additions
# n = 1000 -> 1000 additions
# We call this O(n): double the input, double the work.
Your turn
What does this print?
nums = [4, 8, 15]
steps = 0
for x in nums:
steps += 1
print(steps)Mini quiz
1 / 3