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
BeginnerA simple sorting algorithm that repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order.
Insertion Sort
BeginnerBuilds the sorted array one element at a time by repeatedly taking an element and inserting it into its correct position.
Selection Sort
BeginnerFinds the minimum element from the unsorted portion and places it at the beginning of the sorted portion.
Quick Sort
IntermediateA divide-and-conquer algorithm that picks a pivot element and partitions the array around it, then recursively sorts the sub-arrays.
O(n log n)O(log n)Merge Sort
IntermediateA stable divide-and-conquer algorithm that divides the array into halves, recursively sorts them, and then merges the sorted halves.
O(n log n)O(n)Heap Sort
IntermediateUses a binary heap data structure to sort elements. Builds a max-heap and repeatedly extracts the maximum element.
O(n log n)O(1)Radix Sort
AdvancedA non-comparison based algorithm that sorts numbers digit by digit, from least to most significant digit.
O(d × n)O(n + k)Algorithm Comparison
Quick comparison of time and space complexities
| Algorithm | Best Case | Average Case | Worst Case | Space | Stable |
|---|---|---|---|---|---|
| Bubble Sort | O(n) | O(n²) | O(n²) | O(1) | ✅ Yes |
| Insertion Sort | O(n) | O(n²) | O(n²) | O(1) | ✅ Yes |
| Selection Sort | O(n²) | O(n²) | O(n²) | O(1) | ❌ No |
| Quick Sort | O(n log n) | O(n log n) | O(n²) | O(log n) | ❌ No |
| Merge Sort | O(n log n) | O(n log n) | O(n log n) | O(n) | ✅ Yes |
| Heap Sort | O(n log n) | O(n log n) | O(n log n) | O(1) | ❌ No |
| Radix Sort | O(d×n) | O(d×n) | O(d×n) | O(n+k) | ✅ Yes |