What is Time Complexity (Big-O)?
Time complexity and Big-O notation, told as a story about a ruler that measures how fast work grows as the garage scales up.
What was fine at 10 cars never finishes at 10,000.For some tasks, time grows far faster than the number of cars.
'More cars means proportionally more time' isn't true for every method.How fast the time grows depends entirely on the working method.
Big-O = a ruler for how fast the work grows as cars pile up.Big-O measures the shape of the growth, not one fixed number of seconds.
The gap in step counts between methods explodes as n grows.O(n²) step counts balloon out of hand.
Big-O measures only the shape of the growth, not actual seconds.The actual seconds depend on the gear and situation.
Big-O (time complexity) = a ruler that measures the shape of how fast the work grows as the number of cars (the data) increases.
Time complexity measures how fast an algorithm's running time grows as the input size n increases. O(1) stays constant regardless of input size; O(log n) halves the remaining work each step, as in binary search; O(n) scans everything once; O(n²) compares every pair, growing steeply as n increases. Big-O ignores constant factors and actual hardware speed — it compares only the growth trend.
When grown-ups say it
- O(1)
- Found directly by plate number — always the same time. Time stays flat no matter how much input grows.
- O(log n)
- A search that halves the candidates each step. Time grows very, very slowly as the input grows.
- O(n)
- Checking one by one, down the line. Time grows in proportion to the input size.
- O(n²)
- Comparing every car against every other. Time steepens out of hand as n grows.
- Binary Tree Search (an O(log n) example)
- A shelf map that halves the search at every fork. See what O(log n) actually looks like. → the shelf map that halves the search at every fork
- Stack/Queue push-pop (an O(1) example)
- The rule for stacking boxes or lining up cars. push/pop and enqueue/dequeue are usually O(1). → boxes get stacked, cars get queued
- Cache Hit/Miss
- A hit: the tool is in the toolbox. A miss: it isn't. Even at the same O(1), a hit and a miss feel very different in practice. → the toolbox kept right beside you
- CPU Scheduling
- The rule deciding who gets the lift first. Sorting or searching the job board is measured with this same ruler. → who gets the lift first