final_sol

final_sol - Introduction to Algorithms Massachusetts...

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

View Full Document Right Arrow Icon
Introduction to Algorithms December 23, 2005 Massachusetts Institute of Technology 6.046J/18.410J Professors Erik D. Demaine and Charles E. Leiserson Handout 36 Final Exam Solutions Final Exam Score Distribution 0 2 4 6 8 10 12 14 # of students 50 60 70 80 90 100 110 120 130 140 150 160 170
Background image of page 1

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

View Full DocumentRight Arrow Icon
± ± ² ³ 2 Handout 36: Final Exam Solutions Problem 1. Recurrences [15 points] (3 parts) Give a tight asymptotic upper bound ( O notation) on the solution to each of the following recur- rences. You need not justify your answers. 3 (a) T ( n ) = 2 T ( n/ 8) + n . Solution: ( n 1 / 3 lg n ) by Case 2 of the Master Method. (b) T ( n ) = T ( n/ 3) + T ( n/ 4) + 5 n Solution: ( n ) . 8 T ( n/ 2) + (1) if n 2 > M , (c) T ( n ) = M if n M ; 2 where M is a variable independent from n . Solution: n 3 / M . The recursion tree has approximately lg n lg M = lg n/ M levels. In the tree, every internal node has 8 children, each with cost ± 3 O (1) . At the bottom of the tree, there are approximately 8 lg ( n/ M ) = n/ M leaves. Since each leaf costs M , and the total cost is dominated by the leaves, the ± 3 ± solution is M n/ M = n 3 / M .
Background image of page 2
3 Handout 36: Final Exam Solutions Problem 2. Algorithms and running times [9 points] Match each algorithm below with the tightest asymptotic upper bound for its worst-case running time by inserting one of the letters A, B, . . . , I into the corresponding box. For sorting algorithms, n is the number of input elements. For matrix algorithms, the input matrix has size n × n . For graph algorithms, the number of vertices is n , and the number of edges is ( n ) . You need not justify your answers. Some running times may be used multiple times or not at all. Because points will be deducted for wrong answers, do not guess unless you are reasonably sure. Insertion sort A: O (lg n ) Heapsort B: O ( n ) B UILD -H EAP C: O ( n lg n ) 2 Strassen’s D: O ( n ) 2 Bellman-Ford E: O ( n lg n ) 2 . 5 ) Depth-first search F: O ( n G: O ( n lg 7 ) Floyd-Warshall Johnson’s H: O ( n 3 ) Prim’s I: O ( n 3 lg n ) Solution: From top to bottom: D, C, B, G, D, B, H, E, C.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Handout 36: Final Exam Solutions Problem 3. Substitution method [10 points] Use the substitution method to prove a tight asymptotic lower bound ( Δ -notation) on the solution to the recurrence T ( n ) = 4 T ( n/ 2) + n 2 . Solution: By the master method, we know T ( n ) = ( n 2 lg n ) . Therefore, our induction hypoth- esis is T ( m ) cm 2 lg m for all m < n . For m = 1 , we have the base case that T (1) = 1 > c 1 2 lg 1 for all c > 0 . For the inductive step, assume for all m < n , T ( m ) cm 2 lg m . The induction hypothesis yields T ( n ) = 4 T ( n/ 2) + n 2 ± 2 ± n n 4 c lg + n 2 2 2 2 2 = cn lg n cn 2 lg 2 + n 2 = cn lg n + (1 c ) n 2 . For
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/03/2009 for the course CS 6.033 taught by Professor S during the Spring '09 term at MIT.

Page1 / 22

final_sol - Introduction to Algorithms Massachusetts...

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

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