Big-O Complexity Growth Visualizer — Free Interactive Chart and Calculator

Big-O Complexity Growth Visualizer · Visualizers · Plain HTML, CSS & JS · Live preview

CategoryVisualizers

What's included

Features

Six complexity classes
From O(1) to O(2ⁿ).
Log-scale chart
All curves visible at once.
Live n marker
Dots and labels on each curve.
Operation counts
Formatted with scientific notation for huge values.
Human-readable times
Microseconds to years.
Big-input comparisons
One click for n = 10⁶ and 10⁹.
Example per class
A concrete operation for each.
No libraries
Hand-built SVG chart.

About this UI Snippet

Big-O Notation — What the Growth Classes Mean in Real Time

Screenshot of the Big-O Complexity Growth Visualizer snippet rendered live

Big-O notation describes how the amount of work an algorithm does grows as its input grows. It's easy to memorise "O(n log n) is better than O(n²)", and much more convincing to see how large the gap becomes. This visualizer plots six common complexity classes and translates their operation counts into time.

Log scale, on purpose

The y-axis is logarithmic: each gridline is a thousand times the previous one. On a linear axis, O(2ⁿ) shoots off the chart by n ≈ 20 and flattens every other curve against the floor. On a log axis you can see all six at once — and notice that O(2ⁿ) is a straight line, which is exactly what exponential growth looks like on a log scale.

From operations to seconds

The table converts each class into operations for the chosen n and into time, assuming a million simple operations per second. That's a deliberately simple model: real code has constant factors and caches, but the ranking and the order of magnitude hold. Rows that take over a second turn red.

The big-input buttons

At n = 1,000,000 an O(n log n) sort finishes in about 20 seconds under this model, while an O(n²) algorithm needs around 11 days. At n = 10⁹ the gap becomes the difference between hours and tens of thousands of years. This is why the choice of algorithm dominates micro-optimisation for large inputs.

Examples per class

Each row names a typical operation: constant time for array indexing, logarithmic for binary search, linear for a single loop, n log n for efficient sorting, quadratic for comparing every pair, and exponential for trying every subset.

What Big-O leaves out

Big-O ignores constant factors and lower-order terms. For small n, a "worse" algorithm with a tiny constant can win — which is why sorting libraries switch to insertion sort for short arrays.

Build with AI

Build, Understand, Optimize, and Extend It With AI

Paste this visualizer into an AI assistant like Claude and ask it to explain why an exponential curve is a straight line on a log axis. Ask it to add O(n³) and O(n!) classes, a toggle between linear and log scale, a field to set the operations-per-second assumption, or a mode that times real JavaScript functions (a loop, nested loops, a sort) and plots measured results next to the theory.

Prompt to recreate it

Copy this into your AI assistant of choice to build the effect from scratch, or as a jumping-off point for your own variant:

text
Build a Big-O complexity growth visualizer in plain HTML, CSS and JavaScript with a hand-built SVG chart.

Requirements:
- Six classes: O(1), O(log n), O(n), O(n log n), O(n²) and O(2ⁿ), each with a colour and an example operation.
- Plot all six from n = 1 to 60 on a logarithmic y-axis with gridlines at powers of 1,000 and labelled ticks.
- A slider for n that moves a dashed vertical line and a labelled dot on each curve.
- A table with each class's operation count at n (scientific notation for huge values) and the time at one million operations per second, formatted from microseconds to years, with rows over one second highlighted.
- Buttons for n = 1,000, 1,000,000 and 1,000,000,000 that list the time for each class, describing 2ⁿ at those sizes as longer than the age of the universe.

Want to tighten it up first? Run this prompt through the AI Prompt Studio to score it across 8 quality dimensions, catch anti-patterns, and tune the wording for Claude, ChatGPT, or Gemini before you paste it in.

Source Code

<div class="bo">
  <div class="bo-top">
    <div>
      <h2>How fast does the work grow?</h2>
      <p>Operation counts for common complexity classes, and how long they take at one million simple operations per second.</p>
    </div>
    <label class="bo-n">n = <output id="boNOut"></output>
      <input type="range" id="boN" min="1" max="60" value="20" aria-label="Input size n">
    </label>
  </div>
  <div class="bo-grid">
    <svg id="boSvg" viewBox="0 0 560 340" role="img" aria-label="Growth curves"></svg>
    <table class="bo-table">
      <thead><tr><th>Class</th><th>Example</th><th>Ops at n</th><th>Time</th></tr></thead>
      <tbody id="boRows"></tbody>
    </table>
  </div>
  <div class="bo-scale">
    <span>Big inputs:</span>
    <button type="button" data-n="1000">n = 1,000</button>
    <button type="button" data-n="1000000">n = 1,000,000</button>
    <button type="button" data-n="1000000000">n = 10⁹</button>
    <div id="boBig" class="bo-big" aria-live="polite"></div>
  </div>
</div>

Step by step

How to Use

  1. 1
    Drag nFrom 1 to 60; the dashed line and dots move along every curve.
  2. 2
    Read the tableOperation counts and time at 10⁶ operations per second.
  3. 3
    Watch rows turn redAnything over a second is highlighted.
  4. 4
    Try big inputsButtons compute times for n = 1,000, 10⁶ and 10⁹.
  5. 5
    Note the straight lineExponential growth is linear on a log axis.

Real-world uses

Common Use Cases

Learning Big-O
Build intuition for growth rates.
Interview preparation
Explain trade-offs with real numbers.
Teaching
Show a class why algorithms matter.
Code reviews
Justify replacing a nested loop.
Estimating feasibility
Will this approach finish for our data size?
Related: Sorting Algorithm Visualizer
O(n²) and O(n log n) sorts in action: Sorting Algorithm Visualizer.
Related: Sliding Window Visualizer
Turning O(n²) into O(n): Sliding Window Two-Pointer Visualizer.

Got questions?

Frequently Asked Questions

It describes an upper bound on how an algorithm's work grows with input size n, ignoring constant factors and lower-order terms. O(n) means the work grows proportionally to n; O(n²) means doubling n roughly quadruples the work.

Exponential and quadratic growth become so large that on a linear axis every slower-growing curve looks flat. A log scale compresses large values so all classes can be compared, and it shows exponential growth as a straight line.

Only by a factor of log n, which is about 20 for a million items and 30 for a billion. That's why efficient sorting is practical even for very large inputs.

Not for small inputs. Constant factors, memory access patterns and overhead can make an O(n²) algorithm faster than an O(n log n) one for small n. Big-O describes how cost scales, not the cost at one size.

It is a simple teaching model. Modern CPUs do far more basic operations per second, but real algorithms do more work per step. The comparison between classes, not the absolute time, is the point.