Selection Sort
Last updated
Last updated
Selection sort is a sorting method that uses in-place comparisons. We choose the smallest remaining element and move it to the end of a growing sorted list in this approach. It is one of the most basic sorting algorithms available. The selection sort is well-known for its ease of use. In some instances, it outperforms more sophisticated algorithms.
Time complexity is Ο(n^2), where n is the number of items.
Algorithm
Example,
Let us assume an array A[10]={45,20,40,05,15,25,50,35,30,10}. We have to sort this array using selection sort.
In this algorithm we have to find the minimum value in the list first. Then, Swap it with the value in the first position. After that, Start from the second position and repeat the steps above for the remainder of the list.