◄ WORLD V · SONNY 5DART 502 · a helldive at the net

THE BUBBLE SORT the sort everyone writes first — and everyone is told never to use

Bubble sort walks the list comparing adjacent pairs and swapping the ones out of order, so the largest element “bubbles” to the end each pass; repeat n times and the list is sorted. It is the canonical first sort — two lines of obvious logic — and the canonical bad one: O(n²) comparisons, quadratic and slow. It is stable (equal elements never swap) and needs no extra memory, but for anything real it loses to the O(n log n) sorts. It earns its place as the honest baseline: the sort you understand completely, and outgrow.

THE TECHNIQUE swap adjacent out-of-order pairs, n passes — O(n²), stable

The demo bubble-sorts [5,2,4,1,3] into [1,2,3,4,5] by adjacent swaps: live demo


HISTORY & CREDIT bubble sort · the naive baseline

“Bubble sort is a fine place to start and stop.” — start, yes; it is O(n²), so stop before production. cited

the pass · compare adjacent pairs, swap if out of order — the largest bubbles to the end.
the cost · O(n²) comparisons; stable, in-place, and slow.
the lesson · the sort you understand fully and then leave behind — the honest baseline.

The list combed pair by pair until it is ordered — obvious, stable, and quadratic. resource

RECOMMEND FOR I-13 the bubbled sort, on the compiler

On the canonical compiler, bubble sort turns [5,2,4,1,3] into a sorted list (first 1, last 5):

$ i13 run or_bubblesort.i13 # adjacent swaps, n passes RUN OK · 1028 step(s) · peak stack 6 · call depth 10 is_sorted = 1 first = 1 last = 5
Recommend as a NULL — the resource baseline. Bubble sort produces the same sorted output every sort must, at O(n²) cost — the resource axis (B40) at its most basic. NULL — the sort that opens the batch by being the one everyone writes first.