Selection Sort in C

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 Programming Examples
Insertion Sort in C
Harkiran Kaur
Harkiran Kaur
[email protected]

Harkiran is a Subject Matter Expert. She completed her B.Tech from GTBIT. She is quite gifted academically and obtained AIR 878 in GATE 2018. She is an avid reader and also writes poetry in her free time.

No Comments

Post A Comment