Sorting Selection Sort
Bubble Sort
Insertion Sort
Merge Sort (chap. 14)
Quick Sort (chap. 14)
Heap Sort (chap. 9)
Selection Sort keep selecting the largest number, put it to the last position in sequence ( program 2.12)
worst case complexity O( n2 )
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!
Bubble Sort the largest number(bubble) keeps soaring up
worst case complexity O( n2 )
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!
Insertion Sort selecting numbers, and insert them into the proper positions of a sorted sequence
worst case complexity O( n2 )
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
Description:
Sorting Selection Sort
Bubble Sort
Insertion Sort
Merge Sort (chap. 14)
Quick Sort (chap. 14)
Heap Sort (chap. 9)
Tags:
sort | iteration | number | sequence | pass | the | bubble | worst
Created:
12/15/2002 10:53:34 AM
>
Share this presentation
|
Comments