# HW4_sol - Fall Semester 2008 CS300 Algorithms Solution#4...

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

Fall Semester 2008 CS300 Algorithms Solution #4 1. (a) To show that Quick Sort becomes stable using this transformation, you need to show the following three statements are true; Let T ( i ) be the transformed key of A ( i ) (i.e. T ( i ) = A ( i ) * n + i - 1). i. All transformed keys are distinct: Think that T ( n ) obeys n -based nemeral sys- tem. Then by multiplying n to each A ( i ), the ﬁrst position in n -based nemeral system becomes 0. After adding i - 1 to each A ( i ), all the key values become diﬀerent in the ﬁrst position. Therefore, true. ii. If A ( i ) > A ( j ) then T ( i ) > T ( j ): ( n * A ( i ) + i - 1) - ( n * A ( j ) + j - 1) = n * ( A ( i ) - A ( j )) + ( i - j ) . Since A ( i ) > A ( j ) and i - j < n , above equation is always positive. Therefore, true. iii. If A ( i ) = A ( j ) and i < j then T ( i ) < T ( j ): ( A ( j ) * n + j - 1) - ( A ( i ) * n + i - 1) = j - i. Since i < j , above equation is always positive. Therefore, true. (b) After dividing the transformed key by n , take the quotient only. ± T ( i ) /n ² 2. (a) For each sublist of length k to be sorted by insertion sort in the worst case, it takes T L ( n ) = k - 1 X i =1 i = k ( k - 1) 2 = k 2 2 - k 2 . Since there are

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 02/04/2010 for the course COMPUTER S cs300 taught by Professor Unkown during the Spring '08 term at Korea Advanced Institute of Science and Technology.

### Page1 / 3

HW4_sol - Fall Semester 2008 CS300 Algorithms Solution#4...

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

View Full Document
Ask a homework question - tutors are online