{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

quiz1_practicsol

# quiz1_practicsol - Introduction to Algorithms Massachusetts...

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

Introduction to Algorithms 12 March 2002 Massachusetts Institute of Technology 6.046J/18.410J Professors Piotr Indyk and Charles E. Leiserson Quiz 1 Solutions Quiz 1 Solutions These are the quiz solutions The mean for this quiz was: 65.3 The standard deviation was: 13.2 Problem Points Grade 1 20 2 32 3 22 4 16 Total 90 Name:

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

View Full Document
2 6.046J/18.410J Quiz 1 Solutions Name Problem 1. Recurrences [20 points] Solve the following recurrences (provide only the �() bounds). You can assume T ( n ) = 1 for n smaller than some constant in all cases. You do not have to provide justifications, just write the solutions. T ( n ) = T ( n/ 7) + 1 T ( n ) = (log n ) Master’s Theorem, case 2 T ( n ) = 3 T ( n/ 3) + n T ( n ) = ( n log n ) Master’s Theorem, case 2 T ( n ) = 5 T ( n/ 5) + n log n T ( n ) = ( n log 2 n ) Extended Master’s Theorem, case 2 T ( n ) = 10 T ( n/ 3) + n 1 . 1 T ( n ) = ( n log 3 10 ) Master’s Theorem, case 1
3 6.046J/18.410J Quiz 1 Solutions Name Problem 2. True or False, and Justify [32 points] (8 parts) Circle T or F for each of the following statements to indicate whether the statement is true or false, respectively. If the statement is correct, brieﬂy state why. If the statement is wrong, explain why. Your justification is worth more points than your true-or-false designation. T F The solution to the recurrence log n T ( n ) = T ( n/ 3) + T ( n/ 6) + n is T ( n ) = �( n log n ) (assume T ( n ) = 1 for n smaller than some constant c ). True . First because of the n log n term, T ( n ) n log n . To obtain an upper bound, one can argue that T ( n ) can be shown to be non-decreasing and that an upper bound can be found by solving the recurrence U ( n ) = 2 U ( n/ 3) + n log n , which by the master method leads to U ( n ) = O ( n log n ) . Putting the upper and lower bounds together, we get log n ) . T ( n ) = �( n T F Radix sort works in linear time only if the elements to sort are integers in the range { 1 . . . cn } , for some c = O (1) . False . Radix sort also works in linear time if the elements to sort are integers in the range { 1 , . . . , n d } for any constant d . Note . On page 172 of CLRS, it is shown that radix sort runs in �( d ( n + k )) to sort n d -digit numbers with each digit in the range 0 to k 1 . If we take k = n and d = O (1) , d the running time is O ( n ) , but with d digits in base n , we get a range of n . The main mistake that many people did was to assume that digits were always between 0 and 9.

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

View Full Document
4 6.046J/18.410J Quiz 1 Solutions Name T F There exists a comparison-based sorting algorithm that can sort any 6-element array using at most 9 comparisons. False . A decision tree for sorting a 6-element array has to have at least 6! = 720 leaves, but if we perform at most 9 comparisons, we can get at most 2 9 = 512 leaves which is less than 720. Note . Some people said that the number of comparisons is at least n log 2 n , but this is not correct. The lower bound is log 2 ( n !) which is not n log 2 n (asymptotically, they have the same order of growth).
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern