Sorting Algorithms
Bubble, Insertion, Selection, Merge, Quick, Heap, Cocktail, Shellsort, Timsort, Introsort and Radix Sort as a bar animation with pseudocode highlight and step log.
- Bubble SortInteractive Bubble Sort: bars show every comparison and swap, pseudocode highlights the active line. With best, average and worst-case analysis, stability and use-case notes.
- Insertion SortInteractive Insertion Sort: builds a sorted prefix on the left and shifts each new element into its correct slot. Linear best case, quadratic worst case, stable.
- Selection SortInteractive Selection Sort: each round finds the minimum of the unsorted suffix and swaps it to the front. Exactly n-1 writes, always O(n^2), not stable.
- Merge SortInteractive Merge Sort: recursive halving and stable merging with L and R buffers. Guaranteed O(n log n), stable, ideal as External Sort on data larger than memory.
- Quick SortInteractive Quick Sort: pick a pivot, partition smaller and larger values, recurse on both halves. Average O(n log n), worst case O(n^2), in-place, not stable.
- Heap SortInteractive Heap Sort with tree view: build a max-heap, repeatedly swap the root with the last heap element and run siftDown. Guaranteed O(n log n) and in-place.
- Cocktail SortInteractive Cocktail Sort (Shaker Sort): bidirectional Bubble Sort with forward and backward passes. Tackles the turtle problem, worst case stays O(n^2), stable.
- ShellsortInteractive Shellsort: generalised insertion sort that first sorts far-apart pairs and shrinks the gap to 1. Worst case O(n^2) with the standard gap sequence.
- TimsortInteractive Timsort: hybrid of insertion sort for small runs and stable bottom-up merge. Default sort in Python and Java, worst case O(n log n) and stable.
- IntrosortInteractive Introsort: quick sort that falls back to heap sort once recursion gets too deep, plus insertion sort on tiny ranges. Guaranteed O(n log n), used in std::sort.
- Radix SortInteractive Radix Sort (LSD): stable Counting Sort iterations per digit, base 10 with 10 buckets. Effectively linear O(d · n) for integer keys with bounded digit count.
- Bogo SortInteractive Bogo Sort: joke algorithm that Fisher-Yates-shuffles the array until it is sorted by chance. Expected runtime O(n · n!), worst case unbounded.