Sorting Algorithms

Master SortingAlgorithms Visually

Understand how sorting algorithms work with interactive visualizations. Compare performance and learn complexity analysis.

8+ Sorting Algorithms
Real-time Visualization
Step-by-step Execution
Interactive Visualizations

Choose Your AlgorithmStart Visualizing

Click on any algorithm card to see it in action with interactive step-by-step visualization

Quick Sort

MediumIn-Place

Fast divide-and-conquer algorithm, one of the most efficient general-purpose sorting algorithms.

Average:O(n log n)
Worst Case:O(n²)
Visualize Now

Merge Sort

MediumStable

Guaranteed O(n log n) performance with stable sorting. Predictable and reliable.

Average:O(n log n)
Worst Case:O(n log n)
Visualize Now

Heap Sort

HardIn-Place

In-place sorting with guaranteed O(n log n) performance using heap data structure.

Average:O(n log n)
Worst Case:O(n log n)
Visualize Now

Bubble Sort

EasyStableIn-Place

Simple comparison-based algorithm, good for educational purposes and small datasets.

Average:O(n²)
Worst Case:O(n²)
Visualize Now

Insertion Sort

EasyStableIn-Place

Efficient for small datasets and nearly sorted data. Simple and adaptive.

Average:O(n²)
Worst Case:O(n²)
Visualize Now

Selection Sort

EasyIn-Place

Simple selection-based algorithm with minimal memory writes.

Average:O(n²)
Worst Case:O(n²)
Visualize Now

Shell Sort

MediumIn-Place

Improved insertion sort using gap sequences for better performance.

Average:O(n log n)
Worst Case:O(n²)
Visualize Now

Counting Sort

MediumStable

Non-comparison based linear time sorting for integer ranges.

Average:O(n + k)
Worst Case:O(n + k)
Visualize Now

Radix Sort

HardStable

Processes digits from least to most significant for fixed-length integers.

Average:O(d(n + k))
Worst Case:O(d(n + k))
Visualize Now

Bucket Sort

MediumStable

Distributes elements into buckets for uniformly distributed data.

Average:O(n + k)
Worst Case:O(n²)
Visualize Now

Tim Sort

HardStable

Hybrid algorithm used in Python and Java, excellent for real-world data.

Average:O(n log n)
Worst Case:O(n log n)
Visualize Now

Cocktail Sort

EasyStableIn-Place

Bidirectional bubble sort, slightly better than standard bubble sort.

Average:O(n²)
Worst Case:O(n²)
Visualize Now

Comb Sort

EasyIn-Place

Improvement over bubble sort by eliminating turtles (small values near end).

Average:O(n²/2ᵖ)
Worst Case:O(n²)
Visualize Now

Gnome Sort

EasyStableIn-Place

Simple sorting algorithm similar to insertion sort but moving elements to proper place by swapping.

Average:O(n²)
Worst Case:O(n²)
Visualize Now

Cycle Sort

HardIn-Place

Minimizes the number of memory writes, good when writing to memory is expensive.

Average:O(n²)
Worst Case:O(n²)
Visualize Now

Pancake Sort

MediumIn-Place

Only uses flip operation (reversing elements from beginning to a position).

Average:O(n²)
Worst Case:O(n²)
Visualize Now

Stooge Sort

HardIn-Place

Recursive sorting algorithm with poor efficiency, mainly of academic interest.

Average:O(n^2.7)
Worst Case:O(n^2.7)
Visualize Now

Bogo Sort

EasyIn-Place

Extremely inefficient algorithm that randomly permutes elements until sorted.

Average:O((n+1)!)
Worst Case:O(∞)
Visualize Now

Each algorithm includes interactive visualization, code implementation, and complexity analysis

Complete Collection

All Sorting AlgorithmsDetailed Overview

Explore 18 sorting algorithms with complexity analysis, pros & cons, and use cases

18
Total Algorithms
9
Stable Sorts
13
In-Place Sorts
5
O(n log n) Worst

Complete AlgorithmComparison Table

Compare all 18 sorting algorithms at a glance

AlgorithmCategoryBestAverageWorstSpaceStableIn-Place
Quick SortComparisonO(n log n)O(n log n)O(n²)O(log n)
Merge SortComparisonO(n log n)O(n log n)O(n log n)O(n)
Heap SortComparisonO(n log n)O(n log n)O(n log n)O(1)
Tim SortHybridO(n)O(n log n)O(n log n)O(n)
Bubble SortComparisonO(n)O(n²)O(n²)O(1)
Insertion SortComparisonO(n)O(n²)O(n²)O(1)
Selection SortComparisonO(n²)O(n²)O(n²)O(1)
Shell SortComparisonO(n log n)O(n^1.5)O(n²)O(1)
Cocktail SortComparisonO(n)O(n²)O(n²)O(1)
Comb SortComparisonO(n log n)O(n²/2ᵖ)O(n²)O(1)
Gnome SortComparisonO(n)O(n²)O(n²)O(1)
Cycle SortComparisonO(n²)O(n²)O(n²)O(1)
Pancake SortComparisonO(n)O(n²)O(n²)O(1)
Stooge SortComparisonO(n^2.7)O(n^2.7)O(n^2.7)O(n)
Bogo SortRandomizedO(n)O((n+1)!)O(∞)O(1)
Counting SortNon-ComparisonO(n+k)O(n+k)O(n+k)O(k)
Radix SortNon-ComparisonO(d(n+k))O(d(n+k))O(d(n+k))O(n+k)
Bucket SortNon-ComparisonO(n+k)O(n+k)O(n²)O(n+k)

Legend & Notes

n: Number of elements

k: Range of input values

d: Number of digits

p: Number of increments

Stable: Maintains relative order of equal elements

In-Place: Requires O(1) or O(log n) extra space

∞: Unbounded (may never terminate)