DevTools Hub

Search tools

Search for a developer tool

Algorithms

Sorting Algorithm Visualizer

Watch Bubble, Selection, Insertion, Merge, Quick, and Heap Sort run step by step.

Part of the Algorithms Toolkit
25 elements
6/10
Step 0 / 24In progress
Comparing Swapping Writing Sorted
Comparisons
1
Swaps
0
Writes
0
Worst case
O(n²)

What this shows

Six real sorting algorithms — Bubble, Selection, Insertion, Merge, Quick, and Heap Sort — running step by step on a bar chart, with the comparisons and writes actually counted as they happen. Play through it, step manually, or drag the scrubber to any point in the sort. The comparison and swap counts at the bottom aren't estimates — they're counted from the exact same steps driving the animation, so they're a real measurement of that specific run, not a formula.

The starting arrangement changes the answer

Algorithm Complexity Explained covers best, worst, and average case as a property of which input an algorithm gets, not just its size — the four starting arrangements here (random, sorted, reversed, few unique values) are picked specifically to make that concrete instead of abstract:

What the colors mean

FAQ

Why does Merge Sort's write count look high?

Every element gets copied into a temporary array and then written back into the main array during each merge — that's n writes per merge level, across log n levels, which is exactly where Merge Sort's O(n) auxiliary space and its otherwise excellent O(n log n) guarantee come from. It's the tradeoff: Merge Sort is the only one of these six that can't sort in place.

Is Quick Sort really worse than Merge Sort here?

Only on the sorted preset, and only because of the specific pivot choice this implementation uses (always the last element). A random or median-of-three pivot choice avoids this particular worst case — the takeaway isn't "Quick Sort is bad," it's that an algorithm's average-case reputation can hide a worst case that's one specific, realistic input away.

Where do the Big O values next to each algorithm come from?

See Big O Calculator and Complexity Visualizer for what those growth rates actually mean in operation counts, and Algorithm Complexity Explained for the formal definitions.

Is anything I do here sent anywhere?

No — every sort runs entirely in your browser. Nothing here is ever sent to a server.

Related tools