Sorting Visualizer

"An algorithm must be seen to be believed" — Donald Knuth

Star on GitHub
Speed 50
Size 25
Ready — choose an algorithm and enter or generate an array
Comparisons: 0 Swaps: 0
📊

Generate or enter an array to begin

Unsorted
Comparing A
Comparing B
Sorted

Sorting Algorithms

Explore the characteristics of each algorithm

Bubble Sort

Quadratic

Iteratively compares adjacent elements and swaps them if they are in the wrong order, causing larger elements to "bubble up" to the end of the array.

BestO(n)
AverageO(n²)
WorstO(n²)
SpaceO(1)

Selection Sort

Quadratic

Repeatedly finds the minimum element from the unsorted portion and places it at the beginning. Simple but inefficient for large datasets.

BestO(n²)
AverageO(n²)
WorstO(n²)
SpaceO(1)

Insertion Sort

Quadratic

Builds the sorted array one element at a time by repeatedly picking the next element and inserting it into its correct position.

BestO(n)
AverageO(n²)
WorstO(n²)
SpaceO(1)

Quick Sort

Logarithmic

Uses a divide-and-conquer strategy by selecting a pivot element and partitioning the array so elements less than the pivot are on the left and greater on the right.

BestO(n log n)
AverageO(n log n)
WorstO(n²)
SpaceO(log n)

Merge Sort

Logarithmic

Divides the array into halves, recursively sorts each half, and then merges the sorted halves back together. Guarantees O(n log n) in all cases.

BestO(n log n)
AverageO(n log n)
WorstO(n log n)
SpaceO(n)

Heap Sort

Logarithmic

Builds a max-heap from the array, then repeatedly extracts the maximum element and places it at the end. The heap structure enables efficient selection of the largest element.

BestO(n log n)
AverageO(n log n)
WorstO(n log n)
SpaceO(1)

Shell Sort

Sub-Quadratic

A generalization of insertion sort that allows swapping elements far apart. Uses a gap sequence that shrinks over time, producing fascinating visual "waves" during sorting.

BestO(n log n)
AverageO(n^1.3)
WorstO(n²)
SpaceO(1)

Counting Sort

Linear

A non-comparison sort that counts occurrences of each value, then reconstructs the array. Extremely fast for small ranges of integer values.

BestO(n+k)
AverageO(n+k)
WorstO(n+k)
SpaceO(k)

Radix Sort

Linear

Sorts numbers digit by digit from least significant to most significant using counting sort as a subroutine. Creates mesmerizing wave patterns as digits are processed.

BestO(nk)
AverageO(nk)
WorstO(nk)
SpaceO(n+k)

Tim Sort

Logarithmic

A hybrid algorithm combining insertion sort and merge sort. Splits the array into small "runs", sorts each with insertion sort, then merges them. Used by Python and Java.

BestO(n)
AverageO(n log n)
WorstO(n log n)
SpaceO(n)
VS
Size 30

Algorithm A

Comparisons: 0 Swaps: 0

Algorithm B

Comparisons: 0 Swaps: 0