Selection sort

Time complexity: O(n²).

Result

Examples

How it works

Selection sort finds the smallest remaining item and swaps it into the next position, over and over. It makes few writes but always does n(n-1)/2 comparisons.

When to use it

Teaching, or when writes are very expensive compared to reads.

Other algorithms