Selection Sort
Repeatedly scan the unsorted region for its smallest value and swap it into place. Always makes the same number of comparisons whatever the input — but never more than n swaps, which matters when writing is expensive.
time O(n²) always
space O(1)
Press Tab out of the box or click Resetto regenerate frames from the current input.
Visualization
No frames yet — edit input and click Run.
—
Pseudocode
for i in 0..n-2:
min = i
for j in i+1..n-1:
if a[j] < a[min]: min = j
swap(a[i], a[min])