Selection sort algorithm

   
   
Comparisons done:
Exchanges done:
Legend:
Numbers with this background - sorted elements
Red numbers - smallest element found
Numbers with this background - elements being compared
Black numbers - unsorted elements

The selection sort algorithm works as follows.

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.