Selection sort algorithm
The selection sort algorithm works as follows.
- First, find the smallest element in the array.
- Second, exchange the found element with the element in the first position.
- Then, find the second smallest element (or the smallest element in the rest of the array [not counting
the first element]).
- Then, exchange the found element with the element in the second position.
- Continue in this way until the entire array is sorted.
As you can guess, this method is called selection sort because it works by repeatedly selecting
the smallest remaining element.
Let's compare two versions of the selection sort algorithm.