Big O Complexity

Visualize and compare time complexity curves, with code examples and a speed-improvement calculator

06561.3k2.0k2.6k11121304050n (input size)operationsO(n)O(n²)
Reference n:10

Quadratic — nested loops; doubles input means 4× the work.

// O(n²) — bubble sort
function bubbleSort(arr: number[]): number[] {
  const a = [...arr];
  for (let i = 0; i < a.length; i++) {
    for (let j = 0; j < a.length - i - 1; j++) {
      if (a[j] > a[j + 1]) {
        [a[j], a[j + 1]] = [a[j + 1], a[j]];
      }
    }
  }
  return a;
}

// Two nested loops: every pair of elements
// is compared. n=1000 → ~500,000 comparisons.

Speed Improvement Calculator

If computers became faster, how many more values could the same algorithm handle in the same time? Based on n = 10.

ComplexityOps at n=101,000× faster → n1,000,000× faster → n
O(1)1
O(log n)310k10.0M
O(n)1010k10.0M
O(n log n)333k1.6M
O(n²)10031610k
O(n³)1.0k1001k
O(2ⁿ)1.0k2030
O(n!)3.6M1215
Clicking a row selects it on the graph and switches the code panel. For O(1), faster hardware handles infinite inputs — it's already constant. For O(n!) with large n, values overflow 64-bit floats.