Selection sort algorithm presentation, selection sort example using power point
1.
2. #Presentation submitted to:
Sohrab Hossain, Assistant professor of CSE
FSET,USTC
#Presentation submitted by:
Md Abdul Kuddus
Department of CSE
ID:15010102
Batch:25th
3. #Presentation Name:
Write a program to sort the element of
an array using selection sort.
#What is selection sort??
Repeatedly searches for the largest value in a section of the
data
Moves that value into its correct position in a sorted
section of the list
Uses the Find Largest algorithm
5. *pass 1: compare 1st position with minimum item
After pass1
*pass2: compare 2nd position with next minimum item
After pass2
34 8 64 51 21
8
34 64 51 218
34 64 51 21
8 21 64 51 34
6. *pass3: compare 3rd position with next minimum item
After pass3
*pass4: compare 4th position with next minimum item
After pass4
Array is sorted
8 21 64 51 34
8 21 34 51 64
8 21 34 51 64
8 21 34 51 64
7. *Algorithm:
Algorithm SELECTION(A,N)
Step1 : Repeat steps 2 and 3 for k=1,2,….N-1;
Step2 : Call MIN(A,K,N,LOC).
Step3: [Interchange A[k] and A[LOC].]
Set TEMP:=A[k],
A[k]:=A[LOC] and
A[LOC]:=TEMP.
[End of step 1 loop]
Step4:Exit.
9. int main()
{
int A[1000],k,n;
printf("Enter the number of element you want to Sort : ");
scanf("%d",&n);
printf("Enter Elements in the list : ");
for(k = 0; k < n; k++)
{
scanf("%d",&A[k]);
}
int *sortArray = selectionSort(A,n);
printf("Sorted list : ");
for(k = 0; k < n; k++ )
{
printf("%dt",sortArray[k]);
}
}
10. #Time efficiency
Comparisons: n(n-1)/2
Exchanges: n (swapping largest into place)
Overall: (n2), best and worst cases
#Space efficiency
Space for the input sequence, plus a constant number of local
variables