Big-O Complexity Visualizer
Compare how different algorithmic growth rates scale as input size increases - overlay curves, read live operation counts, and see exactly where one algorithm starts beating another
What is Big-O notation?
Big-O notation describes how the running time (or memory use) of an algorithm grows as the size of its input, usually called n, grows. It deliberately ignores constant factors and lower-order terms, focusing only on the shape of growth as n becomes very large.
For example, an algorithm that does 3n + 5 operations and one that does n operations are both described as O(n) - the constant 3 and the offset +5 don't matter once n is large enough; what matters is that the work scales linearly with input size.
Common complexity classes, ranked best to worst
| Rank | Notation | Name | Typical example | n = 1,000 → ops |
|---|---|---|---|---|
| 1 | O(1) | Constant | Array index lookup | 1 |
| 2 | O(log n) | Logarithmic | Binary search | ≈10 |
| 3 | O(n) | Linear | Single loop / linear search | 1,000 |
| 4 | O(n log n) | Linearithmic | Merge sort, quicksort (avg) | ≈9,966 |
| 5 | O(n²) | Quadratic | Bubble sort, nested loops | 1,000,000 |
| 6 | O(2ⁿ) | Exponential | Naive recursive Fibonacci, subsets | astronomically large |
Operation counts are illustrative, rounded to the nearest whole operation, assuming a leading coefficient of 1.
Reading growth curves
Best, average, and worst case
Many algorithms have different complexities depending on the input. Quicksort, for instance, averages O(n log n) but degrades to O(n²) on already-sorted or adversarial input. When you see a single Big-O figure quoted, check whether it refers to best, average, or worst case.
Crossover points
A curve with a worse asymptotic class can still be faster for small n, because of the constants Big-O ignores. An O(n²) algorithm with a tiny constant factor can outperform an O(n log n) algorithm with a large constant factor when n is small - they only diverge clearly once n grows large. This is why some sorting libraries switch from quicksort to insertion sort for small sub-arrays.
Space vs time complexity
Big-O can describe time (operations performed) or space (memory used). The same notation and growth classes apply to both - this tool visualizes time complexity, but the same curves represent memory growth if you relabel the y-axis.
Using the visualizer
- Select complexity classesClick the chips toggle which growth curves are plotted - O(1), O(log n), O(n), O(n log n), O(n²), and O(2ⁿ). Active chips are filled in their curve color.
- Set the maximum input size (n)Drag the Max n slider to change the upper bound of the x-axis. Small values (10–50) make exponential growth visible without flattening every other curve; large values (1,000+) show how dramatically the classes separate.
- Read live operation countsDrag the Inspect at n = slider to move the vertical reading line. The table below the chart updates to show the exact operation count for each active curve at that input size.
- Toggle log scaleSwitch the y-axis to logarithmic if exponential or quadratic curves are dwarfing the others - this lets you compare curves that grow at very different rates on one chart.
- Check the crossover noteWhen two curves are both active, the note beneath the table tells you the input size at which their growth rates cross, if any, within the current range.
Suggested classroom uses
- Compare your sorting algorithms. Set Max n to 200, enable O(n²) and O(n log n), and ask students to predict which curve represents Bubble Sort versus Merge Sort before revealing the answer.
- Demonstrate the danger of exponential growth. Set Max n to just 30 and enable O(2ⁿ) alongside O(n²) - the chart will make clear why exponential algorithms are infeasible even for modest input sizes.
- Binary search vs linear search. Enable O(log n) and O(n) together, set Max n to 1,000,000, and inspect the table - a striking way to motivate why binary search matters.
- Quiz pairing. Screenshot a chart state (two curves, a marked n) and ask students to identify which curve is which, or to compute the operation count manually and check it against the table.
Growth comparison chart
Reading line at 50Operation counts at n = 50
| Complexity class | Operations | Relative to O(n) |
|---|
