Sorting Algorithm Visualizer
Watch Bubble Sort, Selection Sort, Insertion Sort, Merge Sort, and Quick Sort animate step by step on a bar chart. Comparisons, swaps, and sorted elements are colour-coded so you can follow every operation. No signup, runs entirely in your browser.
Algorithm Comparison Tips
Compare step counts
Set the same array size and run each algorithm. Merge Sort and Quick Sort take far fewer steps than Bubble Sort on large arrays — this makes O(n log n) vs O(n²) tangible.
Slow down for clarity
Set speed to Slow when studying a new algorithm. Watch exactly which elements are compared and swapped at each step before speeding up for the full picture.
Insertion Sort on small arrays
Insertion Sort performs very well on nearly-sorted arrays and small arrays (n < 20). Try it on size 8 — it often beats Merge Sort in raw step count on short inputs.
Stability comparison
Merge Sort and Insertion Sort are stable (equal elements maintain relative order). Quick Sort is typically unstable. Selection Sort is also unstable. Stability matters when sorting objects with multiple keys.
Frequently Asked Questions
Which algorithms are included?
Bubble Sort, Selection Sort, Insertion Sort, Merge Sort, and Quick Sort. These are the five algorithms most commonly covered in introductory computer science courses.
What do the bar colours mean?
Blue bars are being compared in the current step. Orange bars are being swapped. Red indicates the pivot element in Quick Sort. Green bars have been confirmed in their final sorted position.
What is the time complexity of each algorithm?
Bubble, Selection, and Insertion Sort are O(n²) in the worst case. Merge Sort is O(n log n) always. Quick Sort averages O(n log n) but degrades to O(n²) on already-sorted input with a naive pivot choice.
Why does Quick Sort sometimes look slow?
Quick Sort's step count depends on the pivot choices. The worst case occurs when the pivot is always the largest or smallest element. For random arrays (as generated here), Quick Sort is typically fast in practice.
What is the difference between Merge Sort and Quick Sort?
Merge Sort divides the array in half recursively, sorts each half, then merges them — always O(n log n). Quick Sort partitions around a pivot element, which is more cache-friendly but has a worst-case O(n²). In practice, Quick Sort is faster on most real-world data.
Is my data stored?
No. The arrays are generated in your browser and never sent to any server.