Big-O Visualized
Big-O notation answers one question: as the input gets bigger, how fast does the work grow? It ignores constants and hardware and focuses on the shape of the growth — which is what decides whether your code still works at a million items.
What you’ll learn
Section titled “What you’ll learn”- what O(1), O(log n), O(n), and O(n²) mean in practice
- how dramatically they diverge as
ngrows - how to spot each one in real code
The common complexities
Section titled “The common complexities”| Big-O | Name | Grows | Example |
|---|---|---|---|
| O(1) | constant | not at all | dict/set lookup, list[i] |
| O(log n) | logarithmic | very slowly | binary search |
| O(n) | linear | steadily | scanning a list, x in list |
| O(n²) | quadratic | explosively | nested loops, bubble sort |
Watch them diverge
Section titled “Watch them diverge”Same axes, four growth rates. At small n they look similar — but O(n²) shoots off the
chart almost immediately while O(1) and O(log n) barely move:
The lesson: an O(n²) algorithm that’s fine for 100 items can be hopeless at 100,000. When
your data can grow, the Big-O is what matters — not how fast the code feels on a small test.
Try it: Big-O Exercises
Section titled “Try it: Big-O Exercises”Exercise 1 – Constant time O(1)
Section titled “Exercise 1 – Constant time O(1)”Exercise 2 – Linear time O(n)
Section titled “Exercise 2 – Linear time O(n)”Exercise 3 – Quadratic time O(n²)
Section titled “Exercise 3 – Quadratic time O(n²)”pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading