Selection sorting technique
Let me ask you a question, are you someone who keeps forgetting the selection sorting technique?
When someone asks you to write a logic for the selection sort, you go blank and get confused with how to use the selection sorting technique to solve a given problem?
let me tell you a story
When I was in fifth grade, they shuffle class based on scores after each test. Sixty of us are sitting in a class and the teacher will distribute scorecards to all of us. The class is arranged from lowest to highest to focus more on the low scorer.
How does he get the lowest scorer?
In a class of 60 and going through each of the scorecards figuring out the lowest is very hard. He did a technique here, he considered the lowest one to be the first one sitting in a class and asked each one from the beginning.
Is your score less than 50? which is Praneeth’s score, one who is sitting in the beginning. The next guy was Akash and he said YES.
Now Akash became the lowest scorer in the class and it continued until he arranged according to his need.To arrange it took him around 60 minutes. It wasn’t the same as the earlier class. In an earlier class, he was able to do it in 15 minutes.
Why so? he started thinking.
After sometimes he was able to find what was wrong.
In an earlier class, his effort was less. The class was almost in the order he wanted.
Which algorithm did he use? I want you to think for a moment.
He used selection sort.
What did we learn from a story?
When he needs to arrange the entire class, it took him O(n2) but the earlier class wasn’t the same. It took him O(1) time to arrange, when class was already in a order.
When you have more data to arrange the selection sort is inefficient. The teacher thought this is inefficient. He used another technique next time. Which I will write in the next article.