

Now, we will find the next minimum element in array A and swap it with the second element in the array.

Let us say the above array is named as ‘A’, all we need to find is the minimum element one by one, for example, the minimum element in the array ‘A’ as of now is ‘1’, therefore swap the first minimum element in an array with the ‘0th’ index, or the first index, see the below image for better understandability. This is one of the simplest and the most intuitive sorting algorithms, let us take an example to understand the working of selection sort-: Repeat the steps above for the remainder of the list (starting at the second position and advancing each time). Swap it with the value in the first position. The working of selection sort doesn’t require any additional space and it is also scalable This algorithm focuses on finding the minimum elements and then placing them one by one from the starting point of an array and because the minimum elements are swapped with their correct position, the selection sort algorithm is not stable. If the elements to sort are low, i.e in the range of 10-20, selection sort is among the fastest sorting algorithms. Selection sort is a sorting algorithm, specifically an in-place comparison sort, just like the insertion sort. Out of many sorting algorithms, selection sort seems to be very easy to understand, but how does it perform? Is selection sort better than insertion sort? What is the time complexity of the Selection sort? These questions will be answered while we will analyze this sorting algorithm in detail. Sorting is one of the most important concepts in the data structure, it solves the basic yet very vital problem for computer science, the best thing about learning sorting algorithm is that it helps to build the logic step by step, each algorithm is better or worse than the other one in some sense, as of now we will concentrate our focus on selection sort algorithm.
