Selection sort has a simple and satisfying structure — it makes exactly one swap per pass, and after each pass one more element is permanently in its correct position. Watch the green sorted region grow one bar at a time, never touched again.
Each pass starts at the leftmost unsorted position and scans every remaining element to find the smallest. The yellow bar tracks the current best candidate. When the scan finishes, that yellow bar swaps with the first unsorted position — a single red flash — and the pass is done.
This animation also shows the cases where no swap is needed — when the element at the pass start is already the minimum, it stays put. Watch the swap counter: selection sort never makes more than n-1 swaps regardless of the input, which is why it is useful when writes are expensive.
No matter how disordered the input is, selection sort makes at most n−1 swaps — one per pass. This is fewer than any other O(n²) algorithm, making it useful when write operations are costly.
Unlike insertion sort, selection sort gets no benefit from nearly-sorted data. It always scans the entire unsorted region — pass 1 does n−1 comparisons, pass 2 does n−2, and so on. Total: n(n−1)/2.
Swapping the minimum to the front can jump it past equal elements, changing their relative order. Example: sorting [3a, 3b, 1] gives [1, 3b, 3a] — the two 3s are reversed. This disqualifies selection sort where stability matters.
Like insertion sort and bubble sort, selection sort sorts in place using only a constant amount of extra memory — one variable to track the minimum index. No auxiliary array is needed.
TIPWatch the Swaps counter — it barely moves. Selection sort finishes the entire 13-element sort with at most 12 swaps. Compare that to the Comparisons counter which grows rapidly — that is the O(n²) cost showing itself.