Sorting Visualizer

Watch Bubble, Selection, Insertion, Merge, Quick, Heap, and Radix sort race in real time. Adjustable speed, array size, step-through mode, and comparison/swap counters.

Speed:
Array size:60
0
Comparisons
0
Swaps
Ready
Status

Yellow = comparing · Red = swapping · Green = sorted. Try different algorithms and array sizes to compare performance.

What the sorting visualizer shows

Race seven classic sorting algorithms — bubble, insertion, selection, merge, quick, heap, and shell sort — on the same array and watch the bars swap in real time, with live counters for comparisons and swaps. It turns "quicksort is faster" from a claim you memorized into a difference you can see.

How sorting algorithms differ

The split is mostly about time complexity. Bubble, insertion, and selection sort are simple but O(n²) — fine for tiny inputs, painful at scale. Merge, quick, and heap sort are O(n log n) and handle large arrays comfortably. They also differ in memory (merge sort needs extra space; heap sort is in-place) and stability (whether equal elements keep their original order).

Why it matters

Sorting is the most-used building block in programming, and picking the right one — or knowing what your language's built-in sort actually does — affects real performance. It's also the single most common algorithm-interview topic. Keep going with the pathfinding visualizer or test yourself on the coding challenges.

Frequently asked questions

Which sorting algorithm is fastest?

For general-purpose sorting, quicksort is usually fastest in practice; merge sort matches its O(n log n) worst case and is stable. Most language standard libraries use a hybrid (e.g. Timsort).

What is a stable sort?

A stable sort preserves the relative order of equal elements — important when sorting by multiple keys. Merge sort is stable; heap sort and typical quicksort are not.

Why not always use bubble sort?

It's easy to write but O(n²): on 10,000 items it does ~100 million comparisons versus ~130,000 for an O(n log n) sort.