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?

  1. It will select the first element in the array as minimum element.
  2. Then it scans the entire remaining array to find if any other element less than the minimum is present.
  3. If present it changes the minimum’s index to the lesser element.
  4. 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.


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.

source :

#100DaysofCode #SelectionSort



Lives to Learn

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store