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
Bubble Sort
Repeatedly swap neighbouring items that are out of order.
Open simulation →Selection Sort
Pick the smallest remaining item and put it in place.
Open simulation →Insertion Sort
Insert each item into its place in the sorted part, like sorting cards.
Open simulation →Merge Sort
Divide the list in halves, sort each, then merge them.
Open simulation →Quick Sort
Partition around a pivot, then sort each side.
Open simulation →Heap Sort
Build a max-heap, then repeatedly pull out the largest item.
Open simulation →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.