DEV Community

Sudharsanan Ravichandran
Sudharsanan Ravichandran

Posted on

Selection Sort

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

  1. Find the smallest card and swap it with the first element of the array.
  2. Find the second smallest card and swap it with the second element of the array.
  3. 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

implementation

Once after you execute the function below is the response

result

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 😊

Discussion (0)