quiz1sol-ss-1

quiz1sol-ss-1 - Introduction to Algorithms Massachusetts...

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

View Full Document Right Arrow Icon
Introduction to Algorithms February 23, 2005 Massachusetts Institute of Technology 6.046J/18.410J Professors Charles E. Leiserson and Ronald L. Rivest Quiz 1 Solutions Quiz 1 Solutions Problem 1. Recurrences (6 parts) [18 points] Solve the following recurrences by giving tight Θ -notation bounds. You do not need to justify your answers, but any justi±cation that you provide will help when assigning partial credit. (a) T ( n ) = T ( n ) + Θ(lg lg n ) Solution: Change of variables: let m = lg n . Recurrence becomes S ( m ) = S ( m/ 2) + Θ(lg m ) . Case 2 of master’s theorem applies, so T ( n ) = Θ((lg lg n ) 2 ) . (b) T ( n ) = T ( n/ 2 + n ) + 6046 Solution: Ignore n . At each stage, we incur constant cost 6046 , but we half the problem. Therefore T ( n ) = Θ(lg n ) . Or use case 2 of master’s theorem. (c) T ( n ) = T ( n/ 2) + 2 n Solution: Case 3 of master’s theorem, (check that the regularity condition holds), Θ(2 n ) . (d) T ( n ) = nT ( n ) + 100 n Solution: Master’s theorem doesn’t apply here. Draw recursion tree. At each level, do 100 n work. How many levels l are there in the tree? Note that as long as we reduce the problem size to some constant c , we can have the induction hypothesis take care of the running times before the problem size is as big as c . So for instance take c to be 2. Then, we want n (1 / 2) l = 2 (1 / 2) l = 1 / lg n 2 - l = 1 / lg n ⇔ - l = lg(1 / lg n ) l = lg lg n. So guess T ( n ) = Θ( n lg lg n ) and use the substitution method to verify guess. (e) T ( n ) = T ( n/ 5) + T (4 n/ 5) + Θ( n ) Solution: Master’s theorem doesn’t apply here. Draw recursion tree. At each level, do Θ( n ) work. Number of levels is log 5 / 4 n = Θ(lg n ) , so guess T ( n ) = Θ( n lg n ) and use the substitution method to verify guess. (f) T ( n ) = 10 T ( n/ 3) + 17 n 1 . 2 Solution: Since log 3 9 = 2 , so log 3 10 > 2 > 1 . 2 . Case 1 of master’s theorem applies, Θ( n log 3 10 ) .
Background image of page 1

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

View Full DocumentRight Arrow Icon
6.046J/18.410JQuiz1Solutions Name 2 Problem 2. True or False (3 parts) [9 points] Circle T or F for each of the following statements, and brieFy explain why. The better your argument, the higher your grade, but be brief. No points will be given even for a correct solution if no justi±cation is presented. (a) T F There exists a comparison based sorting algorithm that can sort any 6 element array using at most 9 comparisons. Solution: ²alse. Any comparison based sorting algorithm must make at least lg n ! compar- isons in the worst case. ²or n = 6 , lg n ! = lg 720 which lies strictly between 9 and 10 . Thus, at least 10 comparisons in the worst case. (b) T F ²or all asymptotically positive f ( n ) , f ( n ) + o ( f ( n )) = Θ( f ( n )) .
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 01/20/2012 for the course CS 6.006 taught by Professor Erikdemaine during the Spring '08 term at MIT.

Page1 / 7

quiz1sol-ss-1 - Introduction to Algorithms Massachusetts...

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