Selection Sort

Selection sort is another simple but effective sort that trades efficiency for simplicity. Given an array of data, selection sort makes multiple passes of the array, selecting the lowest value in the unsorted part of the array and moves it to the appropriate place in the array.ADS 03 T

SS Pass 1

The objective of pass one is to move the lowest item in the data set to element 0 of the array. Starting at element 0 the lowest value found so far is 35. We then scan element [1] and find that 19 < 35. This means that the new lowest value is 19 and found at element [1].

We scan element [2], and find 19 < 24.

We scan element [3], and discover 19 < 52

We scan element [4], and discover 19 < 46

We scan element [5] and discover 19 ~> 12.  This means that the new lowest value is 12 and can be found at element [5]. We have now reached the end of the data, and stop scanning. The lowest value in the array is 12 and is at element [5].

We are now in the position to be able to exchange element [0] with element [5]. This places 12 into element [0], and 35 in element [5].

ADS 03 UAs the lowest value in the array is in the correct place we can start the second pass.

Next: SS Pass 2