{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

final-practice-sol

final-practice-sol - Introduction to Algorithms...

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

View Full Document Right Arrow Icon
Introduction to Algorithms May 10, 2005 Massachusetts Institute of Technology 6.046J/18.410J Professors Charles E. Leiserson and Ronald L. Rivest Practice Final Exam—From Fall 2004 Practice Final Exam—From Fall 2004 Problem 1. Recurrences (4 parts) [8 points] For each of the recurrences below, do the following: Give the solution using Θ -notation. You need not provide a proof or other justification. Name a recursive algorithm we’ve seen during the term whose running time is described by that recurrence. (a) T ( n ) = T ( n/ 2) + Θ(1) Solution: Θ(log n ) . Binary search. (b) T ( n ) = 2 T ( n/ 2) + Θ( n ) Solution: Θ( n log n ) . M ERGE -S ORT . (c) T ( n ) = T ( n/ 5) + T (7 n/ 10) + Θ( n ) Solution: Θ( n ) . S ELECT (d) T ( n ) = 7 T ( n/ 2) + Θ( n 2 ) Solution: Θ( n lg 7 ) . Strassen’s matrix-multiplication algorithm. Problem 2. Design Techniques and Data Structures (5 parts) [10 points] For each of the following design techniques and data structures, name an algorithm covered this term that uses it. (a) Divide and conquer: Solution: M ERGE -S ORT uses divide and conquer. It divides the problem into two problems of half the size (the left and right halves of the array, conquers the subprob- lems by running M ERGE -S ORT recursively, and combines the results by merging the subarrays together. (b) Dynamic programming: Solution: The typesetting problem used dynamic programming. (c) Greedy: Solution: Prim’s algorithm for minimum spanning tree is a greedy algorithm. (d) Binary search tree: Solution: The dynamic maximum-prefix problem from problem set 4 used an aug- mented red-black tree. (e) FIFO queue: Solution: Breadth-first search uses a FIFO queue.
Image of page 1

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

View Full Document Right Arrow Icon
6.046J/18.410J Practice Final Exam—From Fall 2004 Name 2 Problem 3. True or False, and Justify (12 parts) [84 points] 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, briefly 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 justification is worth more points than your true-or-false designation. (a) T F If f ( n ) is asymptotically positive, then f ( n ) + o ( f ( n )) = Θ( f ( n )) . Solution: True. Clearly, f ( n ) + o ( f ( n )) is Ω( f ( n )) , so let us prove that f ( n ) + o ( f ( n )) = O ( f ( n )) . Let g ( n ) o ( f ( n )) . Then for any c > 0 , there exists n 0 such that g ( n ) c ( f ( n )) for all n n 0 . Hence, f ( n ) + g ( n ) ( c + 1) f ( n ) for all n n 0 , which means that f ( n ) + g ( n ) = O ( f ( n )) . (b) T F An adversary can provide an input to randomized quicksort that will elicit 1 its Θ( n 2 ) worst-case running time. Solution: False. The worst-case behavior of quicksort happens due to bad coin flips; it has nothing to do with the adversary’s choice of inputs. (c) T F Any comparison sort of 5 elements requires at least 7 comparisons in the worst case. Solution: True. The decision tree for sorting 5 elements has 5! = 120 leaves.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern