# lect03 - Lecture 3 Sorting and Selection Comparison Sort In...

This preview shows pages 1–7. Sign up to view the full content.

Lecture 3 Sorting and Selection

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Comparison Sort ree. decision t a as viewed be can sort comparison a Therefore, parts. two into sequence input of ns permutatio all partitions comparison Each sorts. comparison are Quicksort and Heapsort Sort, Merge Sort, Insertion }. ,..., , { sequence input about n informatio order gain to elements between s comparison only use we sort, comparison a In 2 1 n a a a
Decision Tree ? 2 1 a a ? 3 2 a a ? 3 2 a a ? 3 1 a a ? 3 1 a a yes yes yes yes yes 3 , 2 , 1 no no no no no 2 , 3 , 1 2 , 1 , 3 3 , 1 , 2 1 , 3 , 2 1 , 2 , 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Running Time ). lg ( ) ( Thus, ! 2 satisfies ) ( depth its leaves, ! has ree decision t the Since ree. decision t the of height) (or depth the is time running case) (worst the sort, comparison a In ) ( n n n T n n T n n T = Is there a faster sorting of other type?
for - end ; 1 ]] [ [ ]] [ [ ]; [ ]]] [ [ [ begin do 1 downto ] [ for ]; 1 [ ] [ ] [ do to 2 for ; 1 ]] [ [ ]] [ [ do ] [ to 1 for ; 0 ] [ do to 1 for - - + + j A C j A C j A j A C B A length j i C i C i C k i j A C j A C A length j i C k i Counting sort 4 1, 4, 3, 1, 4, 6, 3, : A 1 0, 3, 2, 0, 2, : C 8 7, 7, 4, 2, 2, : C 4, , , , , , , : B 8 7, 6, 4, 2, 2, : C 4 ˆ 1, 4, 3, 1, 4, 6, 3, : A

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
, 1 ˆ 4, 3, 1, 4, 6, 3, : A 4, , , , , 1, , : B 8 7, 6, 4, 2, 1, : C 4 1, , 4 ˆ 3, 1, 4, 6, 3, : A 4, 4, , , , 1, , : B 8 7, 5, 4, 2, 1, : C 4 1, 4, , 3 ˆ 1, 4, 6, 3, : A 4, 4, , 3, , 1,
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 26

lect03 - Lecture 3 Sorting and Selection Comparison Sort In...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online