# lect02 - Lecture 2 Sorting Sorting Problem Input A sequence...

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

Lecture 2 Sorting

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

View Full Document
Sorting Problem . ' ' ' such that sequence input of } ' ,..., ' , ' { n permutatio A : Output }. ,..., , { numbers of sequence A : Input 2 1 2 1 2 1 n n n a a a a a a a a a n Insertion Sort, Merge Sort 6. 5, 4, 3, 2, 1, : Output 3. 1, 6, 4, 2, 5, : Input e.g.,
Efficiency Running time from receiving the input to producing the output. ) log ( ) ( 2 n n O n O Insertion Sort Merge Sort Running time

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

View Full Document
Sort in place Satellite data are usually carried around with the key during sorting the key. A sorting algorithm sorts in place if only a constant number of elements of input array are ever stored outside the array.
key i A i i i A i A key i A i j i j A key A length j + - + - ] 1 [ 1 ] [ ] 1 [ do ] [ and 0 while 1 ] [ do ] [ to 2 for Insertion Sort A array input

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

View Full Document
for. - end ; ] 1 [ while; - end ; 1 ]; [ ] 1 [ begin do ] [ and 0 while ; 1 ]; [ begin do ] [ to 2 for key i A i i i A i A key i A i j i j A key A length j + - + -
Insertion Sort sorts in place.

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

View Full Document
Merge Sort end ); , 1 , ( Sort - Merge begin Program Main ]. ... [ subarray in elements sorts which procedure a be ) , , ( Sort - Merge Let n A r p A r p A
Procedure   then. - end ); , , , ( Merge ); , 1 , ( Sort - Merge ); , , ( Sort - Merge ; 2 / ) ( begin then if ) , , ( Sort - Merge r q p A r q A q p A r p q r p r p A + + <

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

View Full Document
]; [ ] [ do to 1 for ]; 1 [ ] [ do to 1 for 1]; .. 1 [ and 1] .. 1 [ array create ; ; 1 ) , , , ( Merge 2 1 2 1 2 1 j q A j R n j i p A i L n i n R n L q r n p q n r q p A + - + + + - + -
; 1 and ] [ ] [ else 1 and ] [ ] [ hen t ] [ ] [ if do to for ; 1 ; 1 ; ) 1 ( ; ) 1 ( 2 1 + + + + j j j R k A i i i L k A j R i A r p k j i n R n L

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

View Full Document
Is there a sorting algorithm
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 11/03/2010 for the course COMPUTER S CS 6363 taught by Professor Dingzhudu during the Fall '10 term at University of Texas at Dallas, Richardson.

### Page1 / 71

lect02 - Lecture 2 Sorting Sorting Problem Input A sequence...

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

View Full Document
Ask a homework question - tutors are online