previous |
start |
next
Sorting an Array of Integers
- The selection sort algorithm repeatedly finds the smallest
element in the unsorted tail region of the array and moves it to
the front
-
- Array in original order
- Find the smallest and swap it with the first element
- Find the next smallest. It is already in the correct place
- Find the next smallest and swap it with the first element of
unsorted portion
- Repeat
- When the unsorted portion is of length 1, we are done
- This algorithm is slow when run on large data sets
previous |
start |
next