chap8-solutions - Selected Solutions for Chapter 8: Sorting...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Selected Solutions for Chapter 8: Sorting in Linear Time Solution to Exercise 8.1-3 If the sort runs in linear time for m input permutations, then the height h of the portion of the decision tree consisting of the m corresponding leaves and their ancestors is linear. Use the same argument as in the proof of Theorem 8.1 to show that this is impos- sible for m D nŠ=2 , nŠ=n , or nŠ=2 n . We have 2 h ± m , which gives us h ± lg m . For all the possible m ’s given here, lg m D .n lg n/ , hence h D .n lg n/ . In particular, lg 2 D lg N 1 ± n lg n N n lg e N 1 ; lg n D lg N lg n ± n lg n N n lg e N lg n ; lg 2 n D lg N n ± n lg n N n lg e N n : Solution to Exercise 8.2-3 The following solution also answers Exercise 8.2-2. Notice that the correctness argument in the text does not depend on the order in which A is processed. The algorithm is correct no matter what order is used! But the modified algorithm is not stable. As before, in the final for loop an element equal to one taken from A earlier is placed before the earlier one (i.e., at a lower index position) in the output arrray B . The original algorithm was stable because an element taken from A later started out with a lower index than one taken earlier. But in the modified algorithm, an element taken from A later started out with a higher index than one taken earlier. In particular, the algorithm still places the elements with value k in positions CŒk N C 1 through CŒk± , but in the reverse order of their appearance in A .
Background image of page 1

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

View Full DocumentRight Arrow Icon
8-2 Selected Solutions for Chapter 8: Sorting in Linear Time Solution to Exercise 8.3-3 Basis: If d D 1 , there’s only one digit, so sorting on that digit sorts the array. Inductive step: Assuming that radix sort works for d N 1 digits, we’ll show that it works for d digits. Radix sort sorts separately on each digit, starting from digit 1 . Thus, radix sort of d digits, which sorts on digits 1; : :: ; d is equivalent to radix sort of the low-order d N 1 digits followed by a sort on digit d . By our induction hypothesis, the sort of the low-order d N 1 digits works, so just before the sort on digit d , the elements are in order according to their low-order d N 1 digits.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/20/2010 for the course IE ie200 taught by Professor . during the Spring '10 term at 카이스트, 한국과학기술원.

Page1 / 5

chap8-solutions - Selected Solutions for Chapter 8: Sorting...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online