b2KIT

Sorting Algorithm Visualizer

Watch bubble, merge, quick, heap, and radix sort animate step by step. Compare speed and swap counts side by side.

Tested tool guide Tested browser tools Checked August 16, 2026

What Sorting Algorithm Visualizer does, with a checked example

Paste an array of numbers, or let the tool generate one, pick an algorithm from the five offered - bubble, merge, quick, heap, radix - and watch the sort run. The array renders as bars whose heights match the values, each step lights up the elements being compared or swapped, and swap totals tick up as the bars reorder. Running two algorithms side by side on identical input makes their personalities obvious: quicksort jumps across the array, bubble sort shuffles neighbors one position at a time, merge sort visibly assembles from halves. The surprise: the most visually frantic algorithm is rarely the one with the fewest swaps, and neither predicts runtime.

Worked example

A concrete input and expected output from the current implementation.

Input

7, 2, 9, 4 with bubble sort selected

Expected output

Sorted: 2, 4, 7, 9. The animation logs 3 swaps - 7 with 2, then 9 with 4, then 7 with 4 - and stops after a quiet pass finds nothing to swap.

Bubble sort walks the array swapping adjacent pairs that are out of order, and the list has exactly three inversions - (7,2), (7,4), (9,4) - so three swaps remove them all. The passes themselves need six comparisons (three, then two, then one), which is why the animation keeps scanning even after the array looks sorted.

How the result is produced

1

How the animation runs

Each value maps to a bar whose height is the number, so the array reads as a skyline. Play runs the algorithm and pauses at each operation, highlighting the elements currently compared or swapped; step controls advance one operation at a time, and the speed control adjusts how fast passes replay. Swap totals accumulate as the animation runs, and a finished panel shows the fully sorted bars.

2

What each algorithm does

Bubble sort walks the array swapping adjacent out-of-order pairs until a pass makes no changes. Merge sort splits the array in half, recurses, and recombines sorted runs using a temporary array. Quicksort partitions around a pivot. Heapsort builds a max-heap and repeatedly extracts the largest element. Radix sort orders integers digit by digit. Side-by-side panels run all five on the same input, so swap counts and animation length are comparable.

Good uses

  • Studying or teaching the five algorithms: step through quicksort and bubble sort on the same list and watch quicksort's long jumps against bubble sort's one-position shuffles.
  • Interview preparation: predict the next swap before pressing step, then compare your mental model of merge sort's split-and-recombine against what the animation actually shows.
  • Choosing a sort for a concrete input shape - random, nearly sorted, or full of duplicates - by rerunning the five algorithms on generated arrays and comparing swap counts on that exact data.

Limits and checks

  • Swap counts underrate merge sort: its merges move elements through a temporary array rather than by swapping, so the panel with the fewest swaps is not the one that did the least work. Comparison steps and animation length are fairer evidence.
  • Small arrays hide complexity. With a handful of elements all five algorithms look similar, and the O(n^2) versus O(n log n) gap needs hundreds of elements to appear. The speed control changes playback, not computation.
  • The counts describe this tool's implementation, not your code. Quicksort depends on its pivot rule and bubble sort on whether it exits early after a swap-free pass, so a reimplementation can honestly report different swap counts for the same input.

Common questions

Why does bubble sort still scan the array when it has almost nothing to swap?

Swaps are rare on nearly sorted data, but every pass still compares adjacent pairs across the whole array, and those comparisons are the O(n^2) part. On an almost-sorted list bubble sort makes near-minimum swaps yet scans the full array once per pass, so the animation lingers with nothing visibly changing. A quiet final pass is the tell: an early-exit implementation stops after any pass that makes no swaps.

Which of the five is fastest?

It depends on the data. Quicksort is usually fastest on random input but can degrade to O(n^2) on already-sorted data with a poor pivot choice, while merge sort guarantees O(n log n) at the cost of a temporary array. Radix sort can beat every comparison-based sort on short integers. Run all five panels on the same array before trusting a ranking, and remember the speed control changes playback speed, not runtime.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools