Sorting Algorithm Visualizations
Reading about sorting algorithms is one thing. Watching one race through 100 values, every comparison and every swap, is how the intuition actually sticks. Each page below animates the real algorithm at a speed you control: slow it down to follow individual comparisons, or crank it up to see the large-scale shape of the sort emerge.
Every visualization is driven by the exact generator code shown on its page, so what you watch is what you read. Alongside each animation you get the best/average/worst-case complexity, space usage, and stability: the exact table interviewers expect you to know cold.
Bubble Sort
The simplest sort there is: keep swapping neighbors until nothing moves.
- Average
- O(n²)
- Worst
- O(n²)
- Space
- O(1)
- Stable
- Yes
Selection Sort
Find the smallest remaining value, put it where it belongs, repeat.
- Average
- O(n²)
- Worst
- O(n²)
- Space
- O(1)
- Stable
- No
Insertion Sort
Sort the way you sort a hand of cards: slide each new value into place.
- Average
- O(n²)
- Worst
- O(n²)
- Space
- O(1)
- Stable
- Yes
Merge Sort
Divide in half, sort each half, merge. Guaranteed O(n log n), every time.
- Average
- O(n log n)
- Worst
- O(n log n)
- Space
- O(n)
- Stable
- Yes
Quick Sort
Pick a pivot, split around it, recurse. The fastest sort in practice.
- Average
- O(n log n)
- Worst
- O(n²)
- Space
- O(log n)
- Stable
- No
Heap Sort
Build a max-heap, then repeatedly pull the maximum. O(n log n), in place.
- Average
- O(n log n)
- Worst
- O(n log n)
- Space
- O(1)
- Stable
- No