Sorting algorithms-1 — Selection sort

Senan Mehdiyev
2 min readJul 9, 2022

Sorting algorithms are algorithms that sort the values and members of an array, list — (any set with mathematically saying) in our computer or mathematical solutions. I will touch on the most widely used and widespread ones and explain them with examples

Selection Sort

The working logic of this algorithm finds the smallest number in each iteration and sorts it. Of course, on the contrary, it is possible to make not just only the smallest, but the largest one by checking and arranging it in each attempt. Let’s try to understand more clearly by focusing on an example!

The algorithm first checks each value from value 1 to the last value and swaps value 1 with the smallest value. This process will continue until the last value. In the second step, it checks from the 2nd value to the last value and swaps the smallest value with the 2nd value. If the smallest value during the check is itself, no displacement occurs because there is no smaller value to replace. Thus, at each step, it gets closer and closer to being fully arranged, from smallest to largest. Finally, after the last value is checked, the set (list, array, etc.) is ready in sorted form

Working principle of Selection Sort Algorithm
Working principle of Selection Sort Algorithm

You can see my python script of this algorithm as a sample code

Selection Sort Algorithm in Python
Selection Sort Algorithm in Python

When talking about algorithms, it is important to inform about “Time Complexity” so that we understand which one is executed and how long, and overall performance differences (you can see TC of Selection Sort in the table). For this reason, I will give detailed information about “Big O Notation” in another article, that article will cover important details from what “Time Complexity” is in simple terms, to the method of calculation and “Space Complexity” that affects the choice of algorithm, stay tuned! :)

Time Complexity for Selection Sort Algorithm
Time Complexity for Selection Sort Algorithm

If you liked the article or have any ideas, we will be glad if you like the post and comment. Thanks!

--

--

Senan Mehdiyev

Self-motivated, ambitious to work, research, and develop in Data Science/ML/DL, have communicative skills, highly inspired to run with a competitive team