Sorting Visualiser

Step through bubble, insertion, selection, merge and quicksort, and see what each one actually costs.

Step 1 of 410 comparisons0 writes
5031821394257647
comparingwritingfinal positionunsorted

Starting array.

Bubble sort

Pseudocode tracks the animation; the rest is code you can lift

  1. for end ← n−1 down to 1
  2. swapped ← false
  3. for i ← 0 to end−1
  4. if a[i] > a[i+1]
  5. swap a[i], a[i+1]; swapped ← true
  6. 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.