As we continue to look into sorting algorithms we will learn what's Selection Sort today.
Selection Sort is another naive sorting approach, can be used for sorting smaller data sets.
First, let's look at the Pseudo code
For this example, let's imagine we are looking at an unsorted set of cards
- Find the smallest card and swap it with the first element of the array.
- Find the second smallest card and swap it with the second element of the array.
- Repeat finding the next-smallest card, and swapping it into the correct position until the array is sorted.
Simple! isn't it?!
Below is the implementation of Selection Sort in JS
Once after you execute the function below is the response
As I mentioned earlier on the below article.
this video reference was really good to understand how similar Insertion Sort & Selection Sort are.
Hope you like this article, please feel free to share your comments.
Thanks again for stopping by 😊