Selection
sort
Let
A be an array of n elements A[1], A[2], …., A[n]. Our aim is to sort the
numbers in the array in ascending order. The steps are as follows
1) Find
the smallest element position in the list A[1], A[2], …., A[n] say k1
and interchange the values A[1] and A[k1]
2) Find
the smallest element position in the list A[2], A[3], ….., A[n] say k2
and interchange the values A[2] and A[k2].
3) Find
the smallest element position in the list A[3], A[4], ….., A[n] say k3
and then interchange the values A[3] and A[k3]
4) Find
the smallest element position in the list A[n-1] and A[n] say kn-1 and
then interchange the values A[n] and A[kn-1].
Example - Sort
the array A using selection sort
A
= (43, 72, 10, 23, 80, 1, 75)