Sorting Algorithms

Explore different sorting algorithms through interactive visualizations. Compare their performance, understand their mechanics, and see how they work step-by-step.

Bubble Sort

Beginner

A simple sorting algorithm that repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order.

Time Complexity
O(n²)
Space Complexity
O(1)
Properties
StableIn-placeAdaptive
Visualize Algorithm

Insertion Sort

Beginner

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

Time Complexity
O(n²)
Space Complexity
O(1)
Properties
StableIn-placeAdaptive
Visualize Algorithm

Selection Sort

Beginner

Finds the minimum element from the unsorted portion and places it at the beginning of the sorted portion.

Time Complexity
O(n²)
Space Complexity
O(1)
Properties
UnstableIn-placeNon-adaptive
Visualize Algorithm

Quick Sort

Intermediate

A divide-and-conquer algorithm that picks a pivot element and partitions the array around it, then recursively sorts the sub-arrays.

Time Complexity
O(n log n)
Space Complexity
O(log n)
Properties
UnstableIn-placeDivide & Conquer
Visualize Algorithm

Merge Sort

Intermediate

A stable divide-and-conquer algorithm that divides the array into halves, recursively sorts them, and then merges the sorted halves.

Time Complexity
O(n log n)
Space Complexity
O(n)
Properties
StableExternalDivide & Conquer
Visualize Algorithm

Heap Sort

Intermediate

Uses a binary heap data structure to sort elements. Builds a max-heap and repeatedly extracts the maximum element.

Time Complexity
O(n log n)
Space Complexity
O(1)
Properties
UnstableIn-placeHeap-based
Visualize Algorithm

Radix Sort

Advanced

A non-comparison based algorithm that sorts numbers digit by digit, from least to most significant digit.

Time Complexity
O(d × n)
Space Complexity
O(n + k)
Properties
StableNon-comparisonLinear time
Visualize Algorithm

Algorithm Comparison

Quick comparison of time and space complexities

AlgorithmBest CaseAverage CaseWorst CaseSpaceStable
Bubble SortO(n)O(n²)O(n²)O(1)✅ Yes
Insertion SortO(n)O(n²)O(n²)O(1)✅ Yes
Selection SortO(n²)O(n²)O(n²)O(1)❌ No
Quick SortO(n log n)O(n log n)O(n²)O(log n)❌ No
Merge SortO(n log n)O(n log n)O(n log n)O(n)✅ Yes
Heap SortO(n log n)O(n log n)O(n log n)O(1)❌ No
Radix SortO(d×n)O(d×n)O(d×n)O(n+k)✅ Yes