Sorting Visualiser
Step through bubble, insertion, selection, merge and quicksort, and see what each one actually costs.
Step 1 of 410 comparisons0 writes
comparingwritingfinal positionunsorted
Starting array.
Bubble sort
Pseudocode tracks the animation; the rest is code you can lift
- for end ← n−1 down to 1
- swapped ← false
- for i ← 0 to end−1
- if a[i] > a[i+1]
- swap a[i], a[i+1]; swapped ← true
- if not swapped: stop ▸ already sorted
Complexity
- Best
- O(n)
- Average
- O(n²)
- Worst
- O(n²)
- Space
- O(1)
- Stable
- Yes
Repeatedly walks the list swapping neighbours that are out of order. Easy to reason about, and too slow for anything real — but its best case is linear, because a pass with no swaps means the list is already sorted.
About
Each algorithm runs to completion and every read and write is recorded as a frame, so the playback is the real algorithm rather than an animation of one.