Selection Sort Program in C

Write a selection sort program in C. Given an unsorted array, write a c code to sort an array using selection sort.

For example :

Input : {9, 8, 19, 2, 3 }
Output : { 2, 3, 8, 9, 19}

What is Selection Sort?

Selection sort is an in-place comparison technique. In selection sort, we pick minimum element and move an element to it’s correct position. We repeat this process until all the elements are sorted.

The time complexity of selection sort is O(n^2). It is not suitable for large data sets.

Bubble Sort Program in Java

Subscribe Our Tutorials

Get Latest Updates on Facebook

How Selection Sort Works

Selection sort is an in-place comparison sort, in which both searching and sorting take place. In each iteration, we pick the smallest or largest element and move to its proper place . If the size of an array is n then it requires n-1 steps. I have added video tutorial at the end of this post for better understanding.

In the above example, We have 5 elements in an array so it requires 4 steps to sort an array. Here is the Pseudo code for selection sort algorithm.

Selection Sort Program in C

Selection Sort Program in C

 

Selection Sort Program in C

Let’s write a c code to implement selection sort algorithm.

In this video tutorial, I have explained how selection sort works and their implementation using java and c code.

About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.
Tagged , , , . Bookmark the permalink.