Bubble sort: when simplicity teaches more than speed

Neighbour compares and swaps bubble the largest unsorted value to the end each pass. Watch every comparison — the algorithm is honest about its work, which is why students still meet it in the wild.

Press Prepare steps.

for pass = 0 .. n-2
  for j = 0 .. n-2-pass
    if a[j] > a[j+1]: swap

Why keep bubble sort in the curriculum?

It is not the sort you ship to sort a billion rows. It is the sort that makes inversions visible: every swap fixes a local mistake. Once you have watched the tape, insertion sort and quicksort’s partition step feel like answers to different complaints about the same world.