Step by step

Sorting algorithm visualizer

Watch six sorting algorithms work on the same data, step through each comparison and swap, and compare how much work they do.

What the colours mean

The algorithms

Try these experiments

Questions

Which sorting algorithm is the fastest?

For general data, O(n log n) algorithms such as merge sort, quick sort and heap sort. Quick sort is usually fastest in practice; insertion sort wins on small or nearly sorted lists.

What is the time complexity of bubble sort?

O(n²) comparisons in the average and worst case, and O(n) in the best case when the list is already sorted and no swaps happen.

What is a stable sort?

A sort that keeps equal values in their original order. Merge, insertion and bubble sort are stable; quick sort and heap sort as shown here are not.

Can I visualise my own data?

Yes. Type up to 200 positive numbers separated by commas into the box and they become the bars.

Where can I learn more algorithms?

Each algorithm links to a full explanation on this site, and DSA Master for iPhone covers 50+ data structures and algorithms with interactive visualizations.

From the same developer