all_inclusive

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.

Why it matters Big-O lets you compare two algorithms without running them, and predict whether an approach that works fine on 100 items will still work on 10 million.

Common complexity classes, ranked best to worst

RankNotationNameTypical examplen = 1,000 → ops
1O(1)ConstantArray index lookup1
2O(log n)LogarithmicBinary search≈10
3O(n)LinearSingle loop / linear search1,000
4O(n log n)LinearithmicMerge sort, quicksort (avg)≈9,966
5O(n²)QuadraticBubble sort, nested loops1,000,000
6O(2ⁿ)ExponentialNaive recursive Fibonacci, subsetsastronomically 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.

Common mistake Big-O describes a trend as n → ∞, not a guarantee about absolute speed at any specific n. Two algorithms in the same class can still have very different real-world performance due to constants, hardware, and implementation details.

Using the visualizer

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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 50

Operation counts at n = 50

Complexity classOperationsRelative to O(n)

Crossover points

Select two curves to see their crossover point, if one exists within the current range.