BEGINNER · 8 MIN · FREE LESSON
Bubble sort
Small swaps. A sorted array.
Loading interactive lesson…
BEGINNER · 8 MIN · FREE LESSON
Small swaps. A sorted array.
Loading interactive lesson…
Start with the unsorted array.
Each pass compares neighbors; n−1 passes can scan almost n items. A no-swap pass stops early.
Measured reads + comparisons, seed 42. Plotted sample sizes respect each lesson’s explicit input limits.
Keyboard: Space play/pause · ←/→ step · R restart · 1–5 speed. Reduced motion disables transitions.
Like bubbles rising through water, each pass carries the largest remaining value to the right.
Use the player above to run, pause, scrub, or step backwards through a deterministic trace.
Switch to Try mode and predict each operation before revealing its result.
Nested passes make the average and worst cases quadratic. Use best, average and worst presets to compare measured counters. The chart plots actual reads and comparisons for n = 8, 16, 32 and 64.
Choose JavaScript, Python, Java or C++ in the synchronized code panel.
Tiny or nearly sorted inputs and learning stable, in-place sorting.
Do not use it for large random arrays; quadratic comparisons dominate.
Complete the three questions below, then use the module navigation to choose your next lesson.
MAKE IT STICK
Progress saves on this device and merges with your account after sign-in.
0 / 5000 · Saved on this device; synced when signed in.