Upload
dipayan-sarkar
View
170
Download
1
Embed Size (px)
Citation preview
SELECTION SORT
Vipin RamolaPGT Comp. Sc.
KV BalasoreBhubaneswar Region
1
2
OBJECTIVES To learn sorting To learn about Selection Sort – writing
program Application of Selection Sort Advantages & Disadvantages
3
PREVIOUS KNOWLEDGE Variables Loops Functions
4
Sorting Arranging elements/data/items in ascending
or descending order of values. Fundamental problems in computer science
and programming Sorting done to make searching easier Multiple different algorithms to solve the
same problem
5
Selection sort Algorithm
– Search through the list and find the smallest element– swap the smallest element with the first element– repeat starting at second element and find the second
smallest element and so on
Program
6
for(i=0; i< n-1; i++){/* find the index of min element in the unsorted a[j .. n-1] assume the min is the first element */ minIndex=i; // test against elements after j to find the smallest for(j=i+1; j< n; j++) {// if this element is less, then it is the new minimum if(A[j] < A[minIndex]) minIndex = j; }/* iMin is the index of the minimum element. Swap it with the current position */ if(minIndex!=i) { temp = A[i]; A[i]=A[minIndex]; A[minIndex] = temp; }}
7
ANIMATION
8
Applications of Selection Sort In embedded systems In basic mobiles
Advantages & DisadvantagesAdvantagesEasy/simple implementation.Useful when no. of elements are less.Can be used when memory is less.
DisadvantagesIt is slower when no of elements are more.Performance varies with initial order of Input
9
Thank You
10