10
SELECTION SORT Vipin Ramola PGT Comp. Sc. KV Balasore Bhubaneswar Region 1

Selection Sort - Vipin Ramola

Embed Size (px)

Citation preview

Page 1: Selection Sort - Vipin Ramola

SELECTION SORT

Vipin RamolaPGT Comp. Sc.

KV BalasoreBhubaneswar Region

1

Page 2: Selection Sort - Vipin Ramola

2

OBJECTIVES To learn sorting To learn about Selection Sort – writing

program Application of Selection Sort Advantages & Disadvantages

Page 3: Selection Sort - Vipin Ramola

3

PREVIOUS KNOWLEDGE Variables Loops Functions

Page 4: Selection Sort - Vipin Ramola

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

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

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

7

ANIMATION

Page 8: Selection Sort - Vipin Ramola

8

Applications of Selection Sort In embedded systems In basic mobiles

Page 9: Selection Sort - Vipin Ramola

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

Thank You

10