0% found this document useful (0 votes)
10 views

SelectionSort

SelectionSort

Uploaded by

rocky2222e
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

SelectionSort

SelectionSort

Uploaded by

rocky2222e
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 34

Data Structures

Lecture: Selection Sort


By
Mukesh Sharma
Asst. Professor

Lovely Professional University, Punjab


Selection Sort

5 1 3 4 6 2

Comparison

Data Movement

Sorted
Selection Sort

5 1 3 4 6 2

Comparison

Data Movement

Sorted
Selection Sort

5 1 3 4 6 2

Comparison

Data Movement

Sorted
Selection Sort

5 1 3 4 6 2

Comparison

Data Movement

Sorted
Selection Sort

5 1 3 4 6 2

Comparison

Data Movement

Sorted
Selection Sort

5 1 3 4 6 2

Comparison

Data Movement

Sorted
Selection Sort

5 1 3 4 6 2

Comparison

Data Movement

Sorted
Selection Sort

5 1 3 4 6 2

Min

Comparison

Data Movement

Sorted
Selection Sort

1 5 3 4 6 2

Comparison

Data Movement

Sorted
Selection Sort

1 5 3 4 6 2

Comparison

Data Movement

Sorted
Selection Sort

1 5 3 4 6 2

Comparison

Data Movement

Sorted
Selection Sort

1 5 3 4 6 2

Comparison

Data Movement

Sorted
Selection Sort

1 5 3 4 6 2

Comparison

Data Movement

Sorted
Selection Sort

1 5 3 4 6 2

Min

Comparison

Data Movement

Sorted
Selection Sort

1 2 3 4 6 5

Comparison

Data Movement

Sorted
Selection Sort

1 2 3 4 6 5

Comparison

Data Movement

Sorted
Selection Sort

1 2 3 4 6 5

Comparison

Data Movement

Sorted
Selection Sort

1 2 3 4 6 5

Comparison

Data Movement

Sorted
Selection Sort

1 2 3 4 6 5

Comparison

Data Movement

Sorted
Selection Sort

1 2 3 4 6 5

Min

Comparison

Data Movement

Sorted
Selection Sort

1 2 3 4 6 5

Comparison

Data Movement

Sorted
Selection Sort

1 2 3 4 6 5

Comparison

Data Movement

Sorted
Selection Sort

1 2 3 4 6 5

Comparison

Data Movement

Sorted
Selection Sort

1 2 3 4 6 5

Min

Comparison

Data Movement

Sorted
Selection Sort

1 2 3 4 6 5

Comparison

Data Movement

Sorted
Selection Sort

1 2 3 4 6 5

Comparison

Data Movement

Sorted
Selection Sort

1 2 3 4 6 5

Comparison

Data Movement

Sorted
Selection Sort

1 2 3 4 6 5

Min

Comparison

Data Movement

Sorted
Selection Sort

1 2 3 4 5 6

Comparison

Data Movement

Sorted
Selection Sort

1 2 3 4 5 6
DONE!
Comparison

Data Movement

Sorted
Selection Sort
Selection_Sort (A, n)
1. Set j = 0.
2. Repeat 3 & 4 While j < n – 1:
3. Set Min = j and I = j+1.
4. Repeat step 5 while I < n:
5. if(a[i] < a[Min]), then:
Min = i.
[End of step 4 loop.]
6. if (Min != j), then:
7. swap (a[j], a[Min]).
8.[End of step 2 loop.]
9.Return.
Comparison Table of Sorting
Best Average Worst
Case Case Case

Bubble Sort O(n) O(n2) O(n2)


Insertion Sort O(n) O(n2) O(n2)
Selection Sort O(n2) O(n2) O(n2)
Merge Sort O(n log n) O(n log n) O(n log n)
Quick Sort O(n log n) O(n log n) O(n2)
Heap Sort O(n log n) O(n log n) O(n log n)
Questions?

You might also like