Sorting Algorithm Visualizer
Interactive visualizations of popular sorting algorithms with step-by-step execution and code explanations.
AllBasicEfficientSpecial Purpose
Basic
Bubble Sort
Simple algorithm that repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order.
BestO(n)
AverageO(n²)
WorstO(n²)
SpaceO(1)
View Visualization →
Basic
Selection Sort
Simple sorting algorithm that repeatedly finds the minimum element from the unsorted part and puts it at the beginning.
BestO(n²)
AverageO(n²)
WorstO(n²)
SpaceO(1)
View Visualization →
Basic
Insertion Sort
Builds the sorted array one item at a time by comparisons. Efficient for small data sets or nearly sorted arrays.
BestO(n)
AverageO(n²)
WorstO(n²)
SpaceO(1)
View Visualization →
Efficient
Merge Sort
Efficient, stable, divide-and-conquer algorithm. Divides array in half, sorts each half, then merges them.
BestO(n log n)
AverageO(n log n)
WorstO(n log n)
SpaceO(n)
View Visualization →
Efficient
Quick Sort
Divide-and-conquer algorithm that selects a pivot, partitions the array, and recursively sorts the partitions.
BestO(n log n)
AverageO(n log n)
WorstO(n²)
SpaceO(log n)
View Visualization →
Efficient
Shell Sort
Generalization of insertion sort that allows the exchange of items that are far apart, then progressively reduces the gap.
BestO(n log n)
AverageO(n(log n)²)
WorstO(n(log n)²)
SpaceO(1)
View Visualization →
Special Purpose
Radix Sort
Non-comparative integer sorting algorithm that sorts data with integer keys by grouping keys by digits.
BestO(nk)
AverageO(nk)
WorstO(nk)
SpaceO(n+k)
View Visualization →
Special Purpose
Count Sort
Integer sorting algorithm that works by counting the occurrences of each unique element in the array.
BestO(n+k)
AverageO(n+k)
WorstO(n+k)
SpaceO(k)
View Visualization →
Special Purpose
Cyclic Sort
Algorithm specifically designed for sorting a range of numbers, placing each number in its correct position.
BestO(n)
AverageO(n²)
WorstO(n²)
SpaceO(1)
View Visualization →
Efficient
Heap Sort
Comparison-based sorting algorithm that uses a binary heap data structure. Builds a max heap and repeatedly extracts the maximum element.
BestO(n log n)
AverageO(n log n)
WorstO(n log n)
SpaceO(1)
View Visualization →
Special Purpose
Bucket Sort
Distribution sort that divides the elements into buckets and then sorts each bucket individually, often with another algorithm.
BestO(n+k)
AverageO(n+k)
WorstO(n²)
SpaceO(n+k)
View Visualization →