Reqflow
Sorting·Beginner

Selection Sort

Time O(n²)Space O(1)
·

Selection sort divides the array into a sorted part on the left and an unsorted part on the right. Each round it scans the unsorted part for the smallest value and swaps it into the next sorted slot. It always does the same amount of comparison work regardless of the input, and it makes at most n swaps, which is its one real advantage.

Example: Sort 6 numbers in ascending order.

When to use this

See also

← All algorithms