Selection Sort — An Analysis

Lakshmanan Subbiah
2 min readMar 5, 2021

--

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.

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.

source : https://cdn.programiz.com

#100DaysofCode #SelectionSort

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response