selection sort - vipin ramola
TRANSCRIPT
![Page 1: Selection Sort - Vipin Ramola](https://reader036.vdocuments.us/reader036/viewer/2022082906/58f1a2fb1a28abea1f8b45dd/html5/thumbnails/1.jpg)
SELECTION SORT
Vipin RamolaPGT Comp. Sc.
KV BalasoreBhubaneswar Region
1
![Page 2: Selection Sort - Vipin Ramola](https://reader036.vdocuments.us/reader036/viewer/2022082906/58f1a2fb1a28abea1f8b45dd/html5/thumbnails/2.jpg)
2
OBJECTIVES To learn sorting To learn about Selection Sort – writing
program Application of Selection Sort Advantages & Disadvantages
![Page 3: Selection Sort - Vipin Ramola](https://reader036.vdocuments.us/reader036/viewer/2022082906/58f1a2fb1a28abea1f8b45dd/html5/thumbnails/3.jpg)
3
PREVIOUS KNOWLEDGE Variables Loops Functions
![Page 4: Selection Sort - Vipin Ramola](https://reader036.vdocuments.us/reader036/viewer/2022082906/58f1a2fb1a28abea1f8b45dd/html5/thumbnails/4.jpg)
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
![Page 5: Selection Sort - Vipin Ramola](https://reader036.vdocuments.us/reader036/viewer/2022082906/58f1a2fb1a28abea1f8b45dd/html5/thumbnails/5.jpg)
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
![Page 6: Selection Sort - Vipin Ramola](https://reader036.vdocuments.us/reader036/viewer/2022082906/58f1a2fb1a28abea1f8b45dd/html5/thumbnails/6.jpg)
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; }}
![Page 7: Selection Sort - Vipin Ramola](https://reader036.vdocuments.us/reader036/viewer/2022082906/58f1a2fb1a28abea1f8b45dd/html5/thumbnails/7.jpg)
7
ANIMATION
![Page 8: Selection Sort - Vipin Ramola](https://reader036.vdocuments.us/reader036/viewer/2022082906/58f1a2fb1a28abea1f8b45dd/html5/thumbnails/8.jpg)
8
Applications of Selection Sort In embedded systems In basic mobiles
![Page 9: Selection Sort - Vipin Ramola](https://reader036.vdocuments.us/reader036/viewer/2022082906/58f1a2fb1a28abea1f8b45dd/html5/thumbnails/9.jpg)
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
![Page 10: Selection Sort - Vipin Ramola](https://reader036.vdocuments.us/reader036/viewer/2022082906/58f1a2fb1a28abea1f8b45dd/html5/thumbnails/10.jpg)
Thank You
10