The Selection Sort
Logic and Design II
The selection sort is a sorting algorithm that is much more
than the bubble sort. The selection sort algorithm steps
array, moving each value to its final sorted position.
The selection sort algorithm usually performs fewer swaps because it moves
items immediately to their final position in the array.
The selection sort works like this: The smallest value in the array
Is located and moved to element 0. Then, the next smallest value is located
and moved to element 1. This process continues until all of the elements
have been placed in their proper order.
5 7 2 8 9 1
The selection sort scans the array, starting at element 0, and locates the element with
the smallest value. Then, the contents of this element are swapped with the contents of
element 0. In this example, the 1 stored in element 5 is swapped with the 5 stored in element
1 7 2 8 9 5
Array after swapping elements