AlgoScope

Bubble Sort

AlgorithmbeginnerSorting

Swap neighbours that are out of order until each pass floats one value home.

Decision · step 2 of 24Bubble Sort: Seven values
10514223843576jj+15 > 1

5 is larger than 1, so they swap.

Open in the player →or start at step 2

What you will see

COMPARE neighbours -> SWAP if out of order -> the largest settles on the right; sorted region grows from the right.

How bubble sort works →

Cost

BestO(n)
AverageO(n^2)
WorstO(n^2)
SpaceO(1)

Best case O(n) requires the early-exit check on an already sorted array.

Properties

  • ✓ comparison based
  • ✓ stable
  • ✓ in place
  • ✓ adaptive
  • × online

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next, compare two runs.

Screen readers: Cells announce index, value and state (comparing, swapped, sorted); each step announces the comparison outcome and any move.

Reduced motion: Swaps become value crossfades with outline flashes; sorted-region growth is a static span change.

Variants

  • Early Exit Stop when a pass makes no swaps.

Leads to

Topics that need this one first.