Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sorting  Selection Sort  Bubble Sort  Insertion Sort  Merge Sort (chap. 14)  Quick Sort (chap. 14)  Heap Sort (chap. 9)

Similar presentations


Presentation on theme: "Sorting  Selection Sort  Bubble Sort  Insertion Sort  Merge Sort (chap. 14)  Quick Sort (chap. 14)  Heap Sort (chap. 9)"— Presentation transcript:

1 Sorting  Selection Sort  Bubble Sort  Insertion Sort  Merge Sort (chap. 14)  Quick Sort (chap. 14)  Heap Sort (chap. 9)

2 Selection Sort  keep selecting the largest number, put it to the last position in sequence ( program 2.12)  worst case complexity O( n 2 )  eg., a sequence of number: 1, 4, 10, 3, 8, 2 step1:  ^ ^ max=10, 10  2 1, 4, 2, 3, 8, 10 step2: 1, 4, 2, 3, 8, 10 max = 8 step3: 1, 2, 3, 4, 8, 10 max = 4, 4  3 step4: 1, 2, 3, 4, 8, 10 in order, done!

3 Selection Sort

4 Bubble Sort  the largest number(bubble) keeps soaring up  worst case complexity O( n 2 )  eg. a sequence of number: 1, 4, 10, 3, 8, 2 iteration 1: 1, 4, 10, 3, 8, 2 1, 4, 3, 10, 8, 2 1, 4, 3, 8, 10, 2 1, 4, 3, 8, 2, 10 iteration 2: 1, 3, 4, 8, 2, 10  1, 3, 4, 2, 8, 10 iteration 3: 1, 3, 2, 4, 8, 10 iteration 4: 1, 2, 3, 4, 8, 10 iteration 5: 1, 2, 3, 4, 8, 10 no exchange, done!

5 Bubble Sort

6 Insertion Sort  selecting numbers, and insert them into the proper positions of a sorted sequence  worst case complexity O( n 2 )  eg. a sequence of number: 1, 4, 10, 3, 8, 2  pass 1: 1, 4, 10, 3, 8, 2 pass 2: 1, 4, 10, 3, 8, 2 pass 3: 1, 3, 4, 10, 8, 2 pass 4: 1, 3, 4, 8, 10, 2 pass 5: 1, 2, 3, 4, 8, 10

7 Insertion Sort


Download ppt "Sorting  Selection Sort  Bubble Sort  Insertion Sort  Merge Sort (chap. 14)  Quick Sort (chap. 14)  Heap Sort (chap. 9)"

Similar presentations


Ads by Google