quiz1-practicesol

quiz1-practicesol - Introduction to Algorithms...

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

View Full Document Right Arrow Icon
Introduction to Algorithms 21 February 2005 Massachusetts Institute of Technology 6.046J/18.410J Professors Charles E. Leiserson and Ronald L. Rivest Practice Quiz 1 Solutions Practice Quiz 1 Solutions Problem 1. Recurrences Solve the following recurrences by giving tight Θ -notation bounds. (a) T ( n ) = 3 T ( n/ 5) + lg 2 n Solution: By Case 1 of the Master Method, we have T ( n ) = Θ( n log 5 (3) ) . (b) T ( n ) = 2 T ( n/ 3) + n lg n Solution: By Case 3 of the Master Method, we have T ( n ) = Θ( n lg n ) . (c) T ( n ) = T ( n/ 5) + lg 2 n Solution: By Case 2 of the Master Method, we have T ( n ) = Θ(lg 3 n ) . (d) T ( n ) = 8 T ( n/ 2) + n 3 Solution: By Case 2 of the Master Method, we have T ( n ) = Θ( n 2 log n ) . (e) T ( n ) = 7 T ( n/ 2) + n 3 Solution: By Case 3 of the Master Method, we have T ( n ) = Θ( n 3 ) . (f) T ( n ) = T ( n - 2) + lg n Solution: T ( n ) = Θ( n log n ) . This is n/ 2 i =1 lg 2 i n/ 2 i =1 lg i ( n/ 4)(lg n/ 4) = Ω( n lg n ) . For the upper bound, note that T ( n ) S ( n ) , where S ( n ) = S ( n - 1)+lg n , which is clearly O ( n lg n ) .
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.410J Practice Quiz 1 Solutions Name 2 Problem 2. True or False, and Justify Circle T or F for each of the following statements, and briefly explain why. The better your argument, the higher your grade, but be brief. Your justification is worth more points than your true-or-false designation. (a) T F If f ( n ) does not belong to the set o ( g ( n )) , then f ( n ) = Ω( g ( n )) . Solution: False. For example f ( n ) = n sin( n ) and g ( n ) = n cos( n ) . (b) T F A set of n integers in the range { 1 , 2 , . . . , n } can be sorted by R ADIX -S ORT in O ( n ) time by running C OUNTING -S ORT on each bit of the binary representation. Solution: False. This results in Θ(log n ) iterations of counting sort, and thus an overall running time of Θ( n log n ) . (c) T F An adversary can construct an input of size n to force R ANDOMIZED -M EDIAN to run in Ω( n 2 ) time. Solution: False. The expected running time of R ANDOMIZED M EDIAN is Θ( n ) . This applies to any input. Problem 3. Short Solution Give brief , but complete, solutions to the following questions. (a) Consider any priority queue (supporting I NSERT and E XTRACT -M AX operations) in the comparison model. Explain why there must exist a sequence of n operations such that at least one operation in the sequence requires Ω(lg n ) time to execute.
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 / 5

quiz1-practicesol - Introduction to Algorithms...

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