Selection sort repeatedly finds the minimum element and moves it to its correct position.
The idea: Divide the array into sorted (left) and unsorted (right) portions. Find the minimum in the unsorted portion. Swap it to the end of the sorted portion. Repeat.
Walkthrough for :
Find min (), swap with first:
Find min in rest (), swap:
Find min in rest (), swap:
Find min in rest (), already in place: