MaisTools
Developer/

Sorting Algorithm Visualizer

See sorting algorithms in action. Compare Bubble, Selection, Insertion, Quick, Merge and Heap Sort step by step.

Options
Algorithm
Size: 30
10100
Speed: 70%
1100
Visualization
UnsortedComparingSwappingSorted
0
Comparisons
0
Swaps
0
Elements
0/0
Frame

About this tool

Visualize how six classic sorting algorithms work. You see comparisons and swaps in real time, with coloured bars showing exactly what the algorithm is doing at each moment. Useful for understanding how each algorithm behaves, comparing their efficiency visually, and studying for technical interviews or exams.

How to use

  1. Choose an algorithm from the menu.
  2. Adjust the array size and animation speed.
  3. Click Start to watch the sorting animation, or use Step to advance manually.
  4. Watch the number of comparisons and swaps to compare efficiency.

Frequently asked questions

Which algorithm is the fastest?
In general Quick Sort and Merge Sort are the fastest for large arrays (O(n log n) average). Bubble, Selection and Insertion are O(n²) and clearly fall behind as the size grows. Insertion Sort, however, is surprisingly efficient for very small or nearly sorted arrays.
When should I use Bubble Sort?
Practically never in real code. It is taught because it is conceptually simple and easy to implement, but every other algorithm here is better in practice. It has educational value for understanding the idea of sorting by adjacent swaps.
Why does Merge Sort have fewer comparisons than Quick Sort in some cases?
Merge Sort has a guaranteed worst case complexity of O(n log n). Quick Sort is O(n log n) on average but can degrade to O(n²) when the pivot is poorly chosen (for instance, an already sorted array with the pivot at the end). This visualizer uses the last element as the pivot, a simple but not optimal choice.
What do the colours mean?
Grey: bars still to sort. Blue: being compared right now. Dark blue: being swapped. Light blue: already in its final sorted position.