Sorting Algorithm Visualizer
Watch nine sorting algorithms run step by step with live comparison and swap counters, starting from random, sorted, or reversed data.
This tool runs entirely in your browser. Your input is never uploaded.
Bubble sort
Repeatedly walks the array and swaps neighbours that are out of order. Each pass locks the largest remaining value in place, and the run stops early once a full pass makes no swap.
Sorting Algorithm Visualizer
Sorting is the one algorithm every programmer learns and almost nobody can picture. Pick an algorithm, choose a starting order, and press Sort: each comparison, swap and write is replayed on the bars one step at a time.
What you get
- Nine algorithms: bubble, selection, insertion, shell, merge, quick, heap, counting and radix (LSD).
- Five starting orders: random, already sorted, reversed, nearly sorted, and few unique values. Each one exposes a different corner of the complexity story — nearly sorted input flatters insertion sort, reversed input hurts bubble sort, and a small value range lets the non-comparison sorts run in linear time.
- Live counters for comparisons, swaps and writes. These are exact and delay-free, which makes them the honest way to compare two algorithms on the same array. Elapsed time would only measure your speed slider.
- Single step through the run, plus a reset that returns to the original order.
- A short explanation and the best / average / worst complexity, extra space and stability of the selected algorithm.
How the animation works
Each algorithm is written as a generator that emits an event for every comparison, swap and write. The run is recorded first, then replayed, so the animation always matches the real execution and you can step through it without re-running.
Why the counters matter
Bubble sort and selection sort both use O(n²) comparisons, but selection sort performs about n swaps while bubble sort can perform n²/2. On hardware where writes are expensive, that difference decides which one you want. Merge sort and quick sort both average O(n log n), but quick sort's constant factor is usually smaller while merge sort stays stable and never degrades.
Counting sort and radix sort do not compare two elements at all, which is why they escape the Ω(n log n) lower bound for comparison sorts — at the price of extra memory and a restricted value range.
Nothing leaves your browser
Every array is generated locally with a seeded PRNG, so results are reproducible and your data never leaves the page.
Related tools
List Shuffler
Shuffle lines, draw random samples, pick winners, or split lists into balanced groups locally.
Open ToolText Sorter
Sort lines alphabetically, by pinyin, number, length, random order, or custom priority rules, ascending or descending.
Open ToolTyping Speed Test
Measure your typing speed with live WPM, accuracy and consistency stats.
Open Tool