{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

final_sol

final_sol - Introduction to Algorithms Massachusetts...

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

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

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

View Full Document
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 .
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.

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

View Full Document
4 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 c < 1 , this quantity is always greater than cn 2 lg n . Therefore, T ( n ) = Δ( cn 2 lg n ) .
5 Handout 36: Final Exam Solutions Problem 4. True or False, and Justify [35 points] (7 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. The more content you provide in your justification, the higher your grade, but be brief. Your

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}