{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

quiz1sol

# quiz1sol - Introduction to Algorithms Massachusetts...

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

Introduction to Algorithms October 11, 2006 Massachusetts Institute of Technology 6.046J/18.410J Professors Erik Demaine and Madhu Sudan Handout 5 Quiz 1 Solutions Quiz 1 Statistics Median 53 Mean 51.7 Std. Deviation 16.0 Max 79 Problem Parts Points Grade Grader 1 6 12 2 1 13 3 6 30 4 3 25 Total 80

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

View Full Document
Handout 5: Quiz 1 Solutions 2 Problem 1. Asymptotic Running Times [12 points] (6 parts) For each algorithm listed below, give its worst-case running time using Θ -notation, as a function of the specified parameters. If the algorithm is randomized, give its expected running time. You need not justify your answers. (a) [2 points] E XTRACT -M IN in a Min-Heap of n elements. Solution: T ( n ) = Θ(log n ) . (b) [2 points] S TRASSEN S algorithm to multiply n × n matrices. Solution: T ( n ) = Θ( n lg 7 ) . (c) [2 points] R ADIX S ORT on an n -element array of b -bit integers (with optimum choice of radix). Solution: T ( n ) = Θ( n + nb/ (lg n )) .
Handout 5: Quiz 1 Solutions 3 (d) [2 points] R ANDOMIZED Q UICKSORT on an n -element array. Solution: T ( n ) = Θ( n lg n ) . (e) [2 points] H ASH -I NSERT to insert an element into a chaining-based hash table with 2 n slots, a load factor of α = 1 / 2 , and a hash function chosen from a universal hash family. Solution: T ( n ) = Θ(1) . (f) [2 points] D ETERMINISTIC S ELECT to find the median of an n -element array. Solution: T ( n ) = Θ( n ) .

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

View Full Document
Handout 5: Quiz 1 Solutions 4 Problem 2. Recurrences [13 points] Professor M. Onotono has managed to come up with a new variant of Mergesort. It splits an array with n elements into three parts, two of size n/ 4 and one of size n/ 2 . After sorting the subarrays, he can merge all three with just n comparisons. Thus the number of comparisons made by his algorithm, denoted T ( n ) , satisfies the recurrence: T ( n ) 2 T ( n/ 4) + T ( n/ 2) + n, with T (1) = T (2) = 1 . Your task is to complete his analysis by proving a tight upper bound on T ( n ) using O -notation. Solution: We guess that T ( n ) cn lg n for n 2 , and prove it by induction on n . By sloppiness, we assume that n is a power of 2 . The base case n = 2 says that T (2) = 1 c 2 lg 2 = 2 c , which holds provided c 1 / 2 . The base case n = 4 says that T (4) = 2 T (1) + T (2) + 4 = 2 + 1 + 4 = 7 c 4 lg 4 = 8 c , which holds provided c 7 / 8 . For the induction step, where n 8 , assume that T ( n 0 ) cn 0 lg n 0 for all n 0 < n (in particular, for n 0 = n/ 2 4 and n 0 = n/ 4 2 ). Now consider T ( n ) : T ( n ) 2 c ( n/ 4) lg( n/ 4) + c ( n/ 2) lg( n/ 2) + n = c ( n/ 2)(lg n - 2) + c ( n/ 2)(lg n - 1) + n = cn lg n - (3 / 2) cn + n = cn lg n - ((3 / 2) c - 1) n cn lg n provided c 2 / 3 . Thus we can choose
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 10

quiz1sol - Introduction to Algorithms Massachusetts...

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

View Full Document
Ask a homework question - tutors are online