Selection Sort
Learn how to perform selection sort, a famous sorting algorithm.
We'll cover the following...
Overview
Let’s understand selection sort with an example. Look at the figure below.
There are four balls of different sizes. Suppose we are given the task to sort the balls according to their size, i.e., the smallest ball first and the largest ball last. Let’s sort it using selection sort.
First round
In the first round, first place is marked, and the first ball is picked.
- Compare the size of the blue ball with the green ball. The size of the green ball is smaller, so hold the green ball in your hand.
- Compare the size of the green ball with the pink ball. The size of the green ball is smaller, so keep the green ball in your hand.
- Compare the size of the