BEGINNER · 10 MIN · FREE LESSON
Selection sort
Explore selection sort through a visual, step-by-step model.
Loading interactive lesson…
BEGINNER · 10 MIN · FREE LESSON
Explore selection sort through a visual, step-by-step model.
Loading interactive lesson…
Start with the selected input.
Every suffix is scanned to choose its minimum; input order does not remove comparisons.
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 choosing the shortest person from each remaining part of a line, selection sort fixes one position per pass.
Find one minimum at a time. Run best, average, worst and seeded random inputs; the animation is a reversible execution trace.
Pause at each decision and predict the operation before revealing its result. Input arrays are limited to 64 bounded integers.
The comparison count stays quadratic even for a sorted input. Only at most n−1 swaps are needed.
Choose a language in the code panel. The highlighted stage follows the trace; counters record the visualized reads, writes, comparisons and swaps.
Use it when writes are expensive and the input is tiny. It is usually slower than insertion sort on nearly sorted data.
Swapping a distant minimum can reorder equal-key records; this version is not stable.
Test the invariant and complexity below, then compare another algorithm on the same input.
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.