Home › Interview & Career › Sorting Algorithm Visualizer

Sorting Algorithm Visualizer

See how sorting algorithms work, step by step. Animate bubble, selection, insertion, merge, quick and heap sort with live comparison and swap counters, highlighted pseudocode, adjustable speed and array size.

0Comparisons
0Swaps / writes
–Time (avg)
–Extra space

Pseudocode

About

How to use it

Pick an algorithm, press Play and watch the bars. Amber bars are being compared, red bars are being swapped or written, green bars are in their final place. Use Step to move one operation at a time while following the highlighted pseudocode line.

Which sort should you use?

  • Bubble, selection, insertion — O(n²); simple to write, fine for tiny arrays. Insertion sort is very fast on nearly sorted data.
  • Merge sort — always O(n log n) and stable, but needs O(n) extra memory.
  • Quick sort — O(n log n) on average and very fast in practice; O(n²) worst case with bad pivots.
  • Heap sort — O(n log n) worst case with O(1) extra space, but not stable.

Try this

Choose “Nearly sorted” and compare insertion sort with selection sort — count the comparisons. Then try “Reversed” with quick sort (last-element pivot) to see its worst case.

More Interview & Career