Selection sort is a sorting algorithm, specifically an in-place comparison sort. It has O(
n2) time complexity, making it inefficient on large lists, and generally performs worse than the similar insertion sort. Selection sort is noted for its simplicity, and also has performance advantages over more complicated algorithms in certain situations, particularly where auxiliary memory is limited.
AlgorithmThe algorithm works as follows:
- Find the minimum value in the list
- Swap it with the value in the first position
- Repeat the steps above for the remainder of the list (starting at the second position and advancing each time)
Effectively, the list is divided into two parts: the sub list of items already sorted, which is built up from left to right and is found at the beginning, and the sub list of items remaining to be sorted, occupying the remainder of the array.
MANISH SONI CGC MOHALI MCA FIRST SEM