Sorting Algorithm Visualizer

Watch quicksort, merge sort and more sort your numbers, and race two side by side.

Result

Examples

Algorithms

Questions

Which sorting algorithm is fastest?

For general data, quicksort is usually fastest in practice, and merge sort and heapsort guarantee O(n log n). Insertion sort wins on small or nearly sorted lists. Try "Nearly sorted" and race insertion against quicksort.

What does stable mean?

A stable sort keeps equal items in the order they started in. It matters when you sort by one field after another, like by name and then by date.

What do comparisons and writes count?

Comparisons is how many times two items were compared. Writes is how many times a value was put into the list. They show the work each algorithm did on exactly the same input.

Why is quicksort not O(n²) on sorted input here?

This quicksort picks the middle item as its pivot. Picking the first or last item makes sorted input the worst case, which is a common mistake.

Can I sort my own numbers?

Yes. Type up to 300 numbers, separated by commas, spaces or new lines. Decimals and negative numbers are fine.