Tutorials  Articles  Notifications  Login  Signup

Introduction Introduction to Sorting algorithms Selection sort algorithm Bubble sort algorithm Insertion sort algorithm Merge sort algorithm Analysis of merge sort algorithm Quicksort algorithm Analysis of quicksort


Sorting algorithms - Selection sort algorithm







Video credits: MyCodeSchool

 

In our previous lesson, we tried to understand the importance of sorting as a computational problem.

We have so many sorting algorithms designed over a period of time, mostly to improve upon the previously designed algorithms.

Now we will study and analyze these algorithms one by one and the first one that we want to talk about, that we will be covering in this lesson is Selection sort.

 

Selection Sort in my opinion is the simplest sorting algorithm and this is what one would do most intutively.

Ok, so let's get started! Let's think of a simple sorting scenario.

Let's say we have a set of cards, and we want to arrange these cards in increasing order of rank. One simple thing we can do is initially, we keep all the cards in our left hand and then first we can select the minimum card out of these cards and move it to the right hand. Now, once again from whatever card is left in the left hand, we can select the minimum and move it to the right hand, next to previous card in the right hand. We can go on repeating this process.


So, at any stage during the process, the left hand will be an unsorted set of cards and the right hand at any stage will be sorted set of cards. So, in the end, right hand will be a sorted arrangement of cards. Cards will be sorted in increasing order of rank.

This is exaclty how selection sort works. 
 


No problems available for this topic.




HackerFriend Logo

Join the community of 1 Lakh+ Developers

Create a free account and get access to tutorials, jobs, hackathons, developer events and neatly written articles.


Create a free account