The idea of selection sort is rather simple: the next largest (or smallest) element in the array is repeatedly found and moved to its final position in the sorted array. In order to sort the array in increasing order, i.e. the smallest element at the beginning of the array and the largest element at the end, the largest element is selected and moved to the highest index position. This is done by swapping the element at the highest index and the largest element. The effective size of the array is then reduced by one element and the process is repeated on the smaller (sub)array. The process ends when the effective size of the array becomes 1 (an array of 1 element is already sorted).

The Algorithm Pseudocode:

selectionSort (A, N)

put 1 into j -- j is used to step through the B list

repeat until j > N
put minimum(A[j]...A[N],N-j+1) into min
swap A[j], A[min]
add 1 to j
end repeat
return A
end selectionSort


The seletion sort algorithm:
  1. Remove the lowest datum one at a time until the data set is empty.