Selection Sort
In this article we’ll focus in undertanding selection sort.
Selection sort is a simple comparison algorithm with a quadratic runtime of O(n²) time. This algorithm is simple and easy to implement, however it is also very inefficient though not more so than bubble sort!
Selection sort works by looping through the array linearly, selecting the smallest element, and then swapping it to the first position. Then loop again linearly and get the second smallest element, swapping it to the second position, and so on and so forth until the array is completely sorted.
Implementing Selection sort
Let’s look at the code:
It’s a pretty simple sorting algorithm to understand and implement.