The interactive player is loading. If it does not appear, you can still read the explanation below.
How it works
Selection sort scans the entire unsorted suffix for its smallest value, then swaps that value into the next final position. The MIN marker follows the smallest value found so far. The final prefix never moves again.
Every input order needs n(n − 1) / 2 value comparisons: best, average and worst time are all O(n²). Already sorted input needs no swaps, but it still scans every suffix. At most n − 1 swaps are needed. The rotated input [2, 3, …, n, 1] reaches that swap limit; reverse order is not necessarily the input with the most swaps.
This standard swap-based version is not stable. With [2, 2, 1], the first swap puts 1 first but reverses the two 2s. The small # labels show original zero-based indices so you can follow equal values individually.
Empty arrays and single values require no comparisons. The algorithm uses O(1) extra space; the animation stores additional snapshots for playback.