# Sorting algorithms demo (Java)

This Java desktop GUI program shows an animation of various sorting algorithms in action, such as bubble sort or quicksort. It includes these 19 sorting algorithms (listed from fastest to slowest):

- Quicksort (double-ended) (
`O`(`n`log`n`)) - Quicksort (sliding) (
`O`(`n`log`n`)) - Heapsort (
`O`(`n`log`n`)) - Shell sort (~
`O`(`n`^{1.3})) - Comb sort (~
`O`(`n`^{2})) - Rotation merge sort (~
`O`(`n`^{2})) - Insertion sort (with binary search) (
`O`(`n`^{2})) - Insertion sort (
`O`(`n`^{2})) - Bubble sort (
`O`(`n`^{2})) - Cocktail sort (
`O`(`n`^{2})) - Gnome sort (
`O`(`n`^{2})) - Pancake sort (
`O`(`n`^{2})) - Quasi-pancake sort (
`O`(`n`^{2})) - Selection sort (
`O`(`n`^{2})) - Cycle sort (
`O`(`n`^{2})) - Stooge sort (
`O`(`n`^{2.71})) - Stupid sort (
`O`(`n`^{3})) - Bozo sort (~
`O`(`n`^{3}log`n`)) - Slowsort (
`O`(`n`^{log n}))

## Download

Executable JAR file: nayuki-sort-demo.jar

On Windows, simply double click the JAR file to run it. Otherwise, type this on a command line: `java -jar nayuki-sort-demo.jar`

This contains source code for the application classes but no unit tests.

## Source code

Browse the complete source code at GitHub: https://github.com/nayuki/Sorting-algorithms-demo

Or download a ZIP of all the files: https://github.com/nayuki/Sorting-algorithms-demo/archive/master.zip

The code package also includes JUnit test cases for every sorting algorithm to ensure that they are implemented correctly.

The source code is open source under the MIT license.

## Videos

Small array (size 30): bubble sort, cocktail sort, selection sort, insertion sort, insertion sort (binary search), gnome sort, pancake sort, quasi-pancake sort, Shell sort, heap sort, quick sort (double-ended), quick sort (sliding), stupid sort, stooge sort, bozo sort.

Large array (size 300): bubble sort, cocktail sort, selection sort, insertion sort, pancake sort, quasi-pancake sort, Shell sort, heap sort, quick sort (double-ended), quick sort (sliding).

Note that the videos run at different speeds, so the length of the video is not a reliable indicator of the sorting algorithm’s speed. Check the number of comparisons and swaps to see how much work was actually performed by the algorithm.

## More info

- David Galles: Data Structure Visualizations - Comparison Sorting Algorithms, Heap Sort