Visualize how sorting algorithms work step by step. Compare Bubble, Selection, Insertion, Quick, and Merge sort.
| Algorithm | Best | Average | Worst | Space | Stable |
|---|---|---|---|---|---|
| Bubble Sort | O(n) | O(n²) | O(n²) | O(1) | Yes |
| Selection Sort | O(n²) | O(n²) | O(n²) | O(1) | No |
| Insertion Sort | O(n) | O(n²) | O(n²) | O(1) | Yes |
| 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 |
Quick Sort and Merge Sort are generally fastest at O(n log n) average. The optimal choice depends on data characteristics.
A stable sort preserves the relative order of equal elements. Bubble, Insertion, and Merge Sort are stable.
Most programming languages use Tim Sort (a hybrid of Merge and Insertion Sort). JavaScript's Array.sort() is also Tim Sort based.
The Sorting Algorithm Visualizer animates how Bubble, Selection, Insertion, Quick, and Merge Sort work. Adjust array size and speed to compare comparison counts, swap counts, and time complexities.