SortingD1Phase 1arrayadjacent-swapintro

Bubble Sort

Baseline sorting visual to introduce comparisons, swaps, and pass optimization.

Easy Explanation

Bubble Sort repeatedly compares neighboring numbers and swaps them until larger values bubble to the end.

Renderer Mode

`Simple` uses abstract, short-form-friendly visuals. `Advanced` keeps the current detailed view.

Arrays + Grid
Visualizer
O(n)Bubble Sort
Deterministic adjacent comparison and swap playback with pass-by-pass sorted region tracking.

Pass

n/a

Comparisons

0

Swaps

0

Result

Sorting

Ready

Press Play or Step to start execution.

No values available for visualization.
Bubble Sort Implementation
Pseudocode + TypeScript
Reference implementation examples are intentionally abstracted from the playback engine so learners can map concepts to code.
pseudocode
function bubbleSort(values):
  n <- length(values)

  for pass from 0 to n - 2:
    swapped <- false

    for i from 0 to n - pass - 2:
      if values[i] > values[i + 1]:
        swap values[i], values[i + 1]
        swapped <- true

    if swapped == false:
      break

  return values
1.00xNo Run