previous | start | next

## Selection Sort

- Selection sort is based upon finding the minimum value in a range of indices and placing that value at the front of the vector.
- Example: Suppose we start with the following vector.

  > `11` | `9` | `17` | `5` | `12`

- The smallest element is 5, so we place it in the first location in the array. However we cannot lose the 11, so these two elements are swapped.

  > `5` | `9` | `17` | `11` | `12`

- Now take the minimum of the remaining entries a[1] ... a[4]. That value is in the correct place, so no swapping is done.

  > `5` | `9` | `17` | `11` | `12`

- Repeat the process over the unsorted region.

  > `5` | `9` | `11` | `17` | `12`

- Continue until the unprocessed region has length 1. You are done.

  > `5` | `9` | `11` | `12` | `17`

previous | start | next