# Selection Sort — An Analysis

For today, I haven’t prepared much in while starting, but an idea came why don’t we analyze the sorting algorithms. So came today’s blog.

Selection sort is an in place comparison sorting algorithm which is not an efficient one. Actually its worst of all sorting algorithms when concerned with time complexity. Taking O(n2) time complexity even for the best case ( already sorted array)

So what does it do?

- It will select the first element in the array as minimum element.
- Then it scans the entire remaining array to find if any other element less than the minimum is present.
- If present it changes the minimum’s index to the lesser element.
- Then it swaps the element to the current index.

So what the algorithm does is that for every index it will find the appropriate element to be placed in that index. This will be done even though the array is sorted.

Advantages:

The advantage in using selection sort is that this type of sorting use only O(1) memory. But the time complexity is O(n2) in all cases ( best, worst and average).

Another advantage that we can gain in selection sort is that the number of writes that this algorithm performs is O(n) which is lesser than most of the sorting algorithms. This is useful if we run our program in flash memory.

#100DaysofCode #SelectionSort