Big-O describes how an algorithm's work grows as its input n gets large. Two programs can solve the same problem, yet one finishes before lunch while the other outlives the universe — purely because of how their cost scales. Slide n below and watch the gulf between O(1) and O(2ⁿ) open up: the same input that costs one class a handful of steps costs another more steps than there are atoms in the galaxy.
Six complexity classes plotted on one chart. Drag n to sweep the vertical line; the cards below read out the exact number of steps each class needs at that n. The fast curves hug the floor while O(n²) and O(2ⁿ) rocket off the top — flip log scale on to keep the runaways on screen and see them as straight lines.
Every class maps to operations you already use. The right column shows the wall-clock time at a brisk 1 billion steps/second for the n you pick below — turning abstract step counts into seconds, years, and beyond.
| Class | Familiar example | Idea |
|---|---|---|
O(1) | Array index arr[i], hash-map lookup | Cost is constant — independent of n. |
O(log n) | Binary search in a sorted array | Halve the search space each step. |
O(n) | Linear scan / sum a list | Touch every element once. |
O(n log n) | Merge sort, quicksort (avg) | The best general comparison sorts. |
O(n²) | Nested loops, bubble sort | Compare every pair. |
O(2ⁿ) | Enumerate every subset | Each item doubles the work. |
O(n!) | Brute-force travelling salesman | Try every ordering of n items. |
Time to run, at 10⁹ steps/sec, for the chosen n:
| Class | Steps at n | Time @ 1e9/s |
|---|
Big-O is about the shape of growth, not exact stopwatch numbers.
O(n): as
n→∞ the leading term dominates and the 3× and the +7 stop mattering. n² + n + 500
is just O(n²).