loading
loading
loading
Computer Science / Algorithms
Watch comparisons and swaps happen live. Switch algorithms, control speed, and step through manually.
Comparison-based sorting algorithms repeatedly compare pairs of elements and reorder them until the whole sequence is in order. Bubble, selection, and insertion sort all run in O(n²) time in the worst case but differ in how many swaps they perform and whether they're stable.
Almost never these O(n²) algorithms — production code uses Timsort, quicksort, or mergesort. These visualizers exist to build comparison/swap intuition, not for real-world use.
A stable sort preserves the relative order of equal elements. This matters when sorting by one key while wanting to preserve an earlier sort order on another key.