Bubble sort, step by step

Compare neighbors, swap, repeat, watch an array sort itself step by step, with the O(n²) catch.

Bubble sort walks the array comparing each pair of neighbors and swapping them when they're out of order. After one full pass, the biggest value has 'bubbled' to the end, guaranteed. Each following pass locks the next-biggest into place.

It's the friendliest sorting algorithm to understand, and the slowest one you'd ever use: every pass scans nearly the whole array, giving O(n²) time. Real systems use quicksort or mergesort, but bubble sort is where the idea of 'sorting by swapping' clicks.

Remember this

  • Each pass bubbles the largest remaining value to the end
  • Simple to picture; O(n²) makes it impractical for big arrays
  • If a full pass makes no swaps, the array is already sorted

Got a different question? SeaThru generates a fresh video for any topic where systems talk or data structures move.

Ask your own question →

Keep learning