Sorting Algorithm Visualizations: Bubble, Selection, Insertion, Merge, Quick and Heap Sort

Watching a sorting algorithm run is the fastest way to understand it. Each visualization here shows the array as bars, highlights every comparison and swap, counts the operations and explains in words what is happening. Type your own numbers, try sorted, reversed and nearly sorted lists, and compare how the time and space complexity of each algorithm shows up in practice.

6 interactive simulations

Frequently asked questions

Which sorting algorithm is the fastest?

Quick sort, merge sort and heap sort run in O(n log n) on average; quick sort is usually fastest in practice, merge sort is stable and heap sort sorts in place with a guaranteed O(n log n) worst case.

Which sorting algorithms are stable?

Bubble sort, insertion sort and merge sort are stable; selection sort, quick sort and heap sort (in their usual forms) are not.

Why learn the slow algorithms?

Bubble, selection and insertion sort introduce comparisons, swaps and invariants, and insertion sort is still used for small or nearly sorted inputs.

Explore more of the Virtual Lab