Sorting with SelectionSort!

Faizah Ahsan
2 min readDec 22, 2020

What is sorting?

Sorting means arranging systematically in groups; separate according to type, class, etc. We usually think of sorting as sorting numbers, ordering strings alphabetically, or think about ordering people in line or by height or by age or something. In interviews when an interviewer talking about sorting, it is usually about taking an array of numbers and sorting them from least to greatest. This is the type of question usually asked during an interview.

There are few types of sorting algorithms out there. But in this blog we will talk about SelectionSort.

How SelectionSort Works:

You can think of the SelectionSort as the prove me wrong sorting algorithm.

Given an array which we need to sort it and return it.

Here are some temporary variables:

Here are the steps:

  1. From i=0 to < array length
  2. Assume the element at ‘i’ is the least in the array, assign i to ‘indexOfMin’
  3. For i from i + 1 to end of array
  4. See if there is an element with lower value
  5. If the index of the current element and the index of the ‘lowest’ element is not the same, swap them.

--

--

Faizah Ahsan

Junior Full-Stack Web Developer. Looking for opportunities!