The visualizer shows how popular comparison sorts work. Choose an algorithm, enter an array or generate a random set of numbers, then run the whole sort or execute it step by step.
| Algorithm | Average complexity | Memory | Stability | Feature |
|---|---|---|---|---|
| Bubble sort | O(n^2) | O(1) | Yes | Compares adjacent elements |
| Cocktail sort | O(n^2) | O(1) | Yes | Traverses the array in both directions |
| Insertion sort | O(n^2) | O(1) | Yes | Fast on nearly sorted data |
| Gnome sort | O(n^2) | O(1) | Yes | Similar to insertion sort using adjacent swaps |
| Selection sort | O(n^2) | O(1) | No | Few swaps, but many comparisons |
| Comb sort | O(n^2) | O(1) | No | Improves bubble sort with a large gap |
| Shell sort | Depends on the gap sequence | O(1) | No | Sorts by insertion on decreasing gaps |
| Merge sort | O(n log n) | O(n) | Yes | Splits the array and merges sorted parts |
| Quicksort | O(n log n) | O(log n) | No | Partitions the array around a pivot |
| Heapsort | O(n log n) | O(1) | No | Uses a binary heap |
| Tree sort | O(n log n) | O(n) | Yes* | Builds a search tree and traverses it |
| TimSort | O(n log n) | O(n) | Yes | Uses natural runs and merges |
| Smoothsort | O(n log n) | O(1) | No | A heapsort variant, good on nearly sorted data |
Comments