Selection Sort

What is Selection Sort?

Selection sort is a sorting algorithm that sorts a collection of elements by selecting the smallest element in the collection and then swapping it with the first element in the collection.

How to implement Selection Sort?

To implement selection sort, we need to select the smallest element in the collection and then swap it with the first element in the collection.

Example

Let's sort the collection [3, 2, 4, 1, 2, 1] using selection sort.

First, we need to select the smallest element in the collection and then swap it with the first element in the collection.

ElementSelectionSwap
311
211
411
111
211
1

The sorted collection is [1, 1, 2, 2, 3, 4].

Heart with ribbonBecome a SponsorHeart with ribbon

Become a sponsor and help us maintain and improve this project. Every contribution counts. Thank you!