Selection Sort in C

Let us see how to implement Selection Sort in C Language.

What is Selection Sort?

The selection sort is a sorting method that yields a sorted array. It does so by repeatedly finding the smallest element in the array and interchanging it with the element at the starting of the unsorted part.

Given example explains the steps required in Selection Sort.

The array before sorting starts is:

Now, the smallest element in this array is 1 which is at position 3. This element is interchanged with 3 at position 0. So the array obtained is:

After the above step, first element of the array is sorted. Out of the remaining 4 elements, the smallest element is 2, at position 4. This is exchanged with 9 which is at position 1. The array obtained is:

The first 2 elements of the array are sorted. Out of the remaining elements, smallest is 3 at position 3. This is replaced with 5 at position 2. The array obtained is:

Finally the sorted array is obtained. This is given as:

Source Code

The source code for Selection Sort is as follows:


The output obtained for the above code is:

Selection Sort

C Online Quiz 1
Insertion Sort in C
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading