The selection sort algorithm sorts an array by repeatedly finding the minimum element (considering ascending order) from unsorted part and putting it at the beginning. The algorithm maintains two subarrays in a given array.
In every iteration of selection sort, the minimum element (considering ascending order) from the unsorted subarray is picked and moved to the sorted subarray.
procedure selectionSort( A : array of items )
n = length(A)
for i = 0 to n-1 do
/* find the minimum element in the unsorted array */
/* swap the found minimum element with the first element */
done
Best Case: Ω(n^2)
Average Case: Θ(n^2)
Worst Case: O(n^2)
Worst Case: O(1)