Selection sort method, implementing the Selection sort
Write C program for implementing the Selection sort method to arrange a list of integers in ascending order.

1. Selection sort is a sorting algorithm, specifically an in-place comparison sort.
2. It has O(n2) time complexity, making it inefficient on large lists
3. Generally performs worse than the similar insertion sort.
4. Selection sort is noted for its simplicity, and also has performance advantages over more complicated algorithms in certain situations, particularly where auxiliary memory is limited.

The algorithm works as follows:
1. Find the minimum value in the list
2. Swap it with the value in the first position
3. Repeat the steps above for the remainder of the list (starting at the second position and advancing each time)

Complexity of Selection Sort
Best Case: O ( n2 )
Average Case: O ( n2 )
Worst Case: O ( n2 )

1. Algorithm:
void selectionsort(int a[20],int n)
Step1 : Start
Step2: Declare variables i,j,k,min,temp
Step3: i=0, i<n-1,i++ repeat step3 to step 11
Step4: min=i;
Step 5: for(j=i+1;j<n;j++) repeat step5 to step 7
Step6: if(a[min]>a[j])
Step7: min=j;
Step8: temp=a[i];
Step9: a[i]=a[min];
Step10: a[min]=temp;
Step11: Stop

2. Algorithm: 
step1: start

step2: declare i,n,a[10]
step3: Read the size of an array
step4: Read the elements of an array
step5: call sub function selectionsort(a,n);
step6: print sorted elements of an array a[i]
step7: stop

Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:


Mukesh Rajput