Selection sort repeatedly finds the minimum element from unsorted part and puts it at the beginning. O(n 2) average and worst. The selection sort minimizes the number of swaps, but the number of comparison is still high. For data that is already sorted or almost sorted, the insertion sort does better.


Source code

Java

Javascript

Python

Doodle

selection sort doodle

Download Java, JavaScript and Python code
Selection sort animated