final - December 19, 2006 6.046J/18.410J Handout 9...

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

View Full Document Right Arrow Icon
Introduction to Algorithms December 19, 2006 Massachusetts Institute of Technology 6.046J/18.410J Professors Erik Demaine and Madhu Sudan Handout 9 Final Exam Solutions Problem Parts Points Grade Grader 1 16 80 2 3 20 3 4 30 4 4 30 5 4 20 Total 180
Background image of page 1

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

View Full DocumentRight Arrow Icon
Handout 9: Final Exam Solutions 2 Problem 1. True or False, and Justify [80 points] (16 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, 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. T F For every two positive functions f and g , if g ( n ) = O ( n ) , then f ( g ( n )) = O ( f ( n )) . Solution: False. Let f ( n ) = 2 n and g ( n ) = 2 n = O ( n ) . Then f ( g ( n )) = 2 2 n = (2 n ) 2 = ( f ( n )) 2 6 = O ( f ( n )) . T F Suppose f ( n ) = 4 f ( n/ 4) + n for n > 8 , and f ( n ) = O (1) for n 8 . Similarly, suppose g ( n ) = 3 g ( n/ 4) + n lg n for n > 8 , and g ( n ) = O (1) for n 8 . Then f ( n ) = Θ( g ( n )) . Solution: True. By the Master Method (Cases 1 and 3), both are Θ( n lg n ) .
Background image of page 2
Handout 9: Final Exam Solutions 3 T F Suppose that a randomized algorithm A has expected running time Θ( n 2 ) on any input of size n . Then it is possible for some execution of A to take Ω(2 n ) time. Solution: True. Consider a (somewhat dumb) sorting algorithm that first sorts n items using mergesort, in time Θ( n lg n ) , and then flips n (fair) coins. If at least one coin turns up heads, the algorithm waits n 2 additional units of time before terminating. If all coins turn up tails, it waits 2 n units of time. Although in the latter case the running time is Ω(2 n ) , the expected running time is only Θ( n lg n ) + (1 - 2 - n )( n 2 ) + 2 - n (2 n ) = Θ( n 2 ) . T F Suppose we maintain a hash table with m slots using chaining and a hash function chosen from a universal hash family. If we insert n > m keys into this (initially empty) hash table, then the total number of collisions is O ( n/m ) in expectation. (Recall that a collision is a pair of distinct keys that hash to the same slot.) Solution: False. In expectation, any particular key x collides with Θ( n/m ) other keys. Thus, summing over all n keys, we have a total of Θ( n 2 /m ) 6 = O ( n/m ) collisions.
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 9: Final Exam Solutions 4 T F Building an n -element heap requires Θ( n lg n ) time. Solution: False. It takes Θ( n ) time. See CLRS, pages 133–135. T F Given an unsorted array A of n integers, let x i denote the 2 i th smallest element in A . Then we can compute b lg n c X i =0 x i in O ( n ) time.
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.

Page1 / 20

final - December 19, 2006 6.046J/18.410J Handout 9...

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