DEV Community

Cover image for Sorting algorithms: JavaScript - Selection Sort🚀
devlazar
devlazar

Posted on

Sorting algorithms: JavaScript - Selection Sort🚀

Table Of Contents
* 🤓INTRODUCTION
* 👉🏻ABOUT SELECTION SORT ALGORITHM
* 👀VISUALIZATION
* 🛠IMPLEMENTATION
* 👩🏻‍💻CODE
* 🙏THANK YOU

🤓 INTRODUCTION

Hello, my dear coders! I hope you are all having a wonderful time coding and enjoying your life. In this blog article, we will discuss the selection sort algorithm using javascript. Connect with me via Twitter or LinkedIn

Let's dive in! 🚀
hack

👉🏻 ABOUT SELECTION SORT ALGORITHM

The Selection sort algorithm is based on the idea of finding the minimum or maximum element in an unsorted array and then putting it in its correct position in a sorted array. In other words, we are finding an index of an element with the smallest value in an entire vector data, and it changes its place with the first element. After that, we are searching for an element with the smallest value in the remaining part of the vector data and it's being placed in the second place.

Assume that the array `array = [9, 5, 6, 12] needs to be sorted in ascending order.

The minimum element in this array is 5, we find an element with the value of 5, and then swap places with the element that is currently located at the first position. Now, the minimum element is an element with a value of 6, which we put in a second position, and so on...It's pretty easy for us humans, well, for computers is different, we need to teach them everything! 😂

👀 VISUALIZATION

Let's visualize sorting of our previously mentioned array; array = [9, 5, 6, 12];

Alt Text

🛠 IMPLEMENTATION

Alt Text

👩🏻‍💻 CODE

Play with code! 🚀

🙏 THANK YOU FOR READING!

References:
School notes...
School books...

Please leave a comment, tell me about you, about your work, comment your thoughts, connect with me!

☕ SUPPORT ME AND KEEP ME FOCUSED!
Buy Me a Coffee at ko-fi.com

Have a nice time hacking! 😊

Top comments (0)