The ones who are crazy enough to think they can change the world are the ones who do.
- Steve Jobs

Selection Sort

Selection sort algorithm is also called as Exchange sort algorithm. The technique of sorting selection sort algorithm is very simple as shown below.

step 1: It search for the first smallest element in the array and swap it with a element array[0].

step 2: Then it search for second smallest element in the array and swap it with a element array[1].

step 3: This process will be repeated until the n-1 element in an array is sorted.

Advantages - Selection Sort

  • Selection sort algorithm is 60% more efficient than bubble sort algorithm.
  • Selection sort algorithm is easy to implement.
  • Selection sort algorithm can be used for small data sets, unfortunately Insertion sort algorithm best suitable for it.

Disadvantages - Selection Sort

  • Running time of Selection sort algorithm is very poor of 0 (n2).
  • Insertion sort algorithm is far better than selection sort algorithm.

C program - Selection Sort

Here is the program to demonstrate Selection Sort.

selection-sort.c
#include <stdio.h>
int smallest (int arry[], int k, int n);
void selection_sort(int arry[], int n);
int main()
{
int arry[10],i,n;
printf("\n Enter the size of the array : ");
scanf("%d", &n);
printf("\n Enter %d elements in the array : \n",n);
for(i=0; i
Enter the size of the array : 5 
Enter 5 elements in the array :
4 3 1 2 5 
Sorted Array in ascending order is : 
1 2 3 4 5

Report Us

We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.

Report

We to update you