This preview shows pages 1–5. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 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 Handout 5: Quiz 1 Solutions 2 Problem 1. Asymptotic Running Times [12 points] (6 parts) For each algorithm listed below, give its worstcase 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] EXTRACTMIN in a MinHeap of n elements. Solution: T ( n ) = (log n ) . (b) [2 points] STRASSENS algorithm to multiply n n matrices. Solution: T ( n ) = ( n lg 7 ) . (c) [2 points] RADIX SORT on an nelement array of bbit integers (with optimum choice of radix). Solution: T ( n ) = ( n + nb/ (lg n )) . Handout 5: Quiz 1 Solutions 3 (d) [2 points] RANDOMIZED QUICKSORT on an nelement array. Solution: T ( n ) = ( n lg n ) . (e) [2 points] HASHINSERT to insert an element into a chainingbased 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] DETERMINISTIC SELECT to find the median of an nelement array. Solution: T ( n ) = ( n ) . 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 Onotation. 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 ) cn lg n for all n < n (in particular, for n = n/ 2 4 and n = n/ 4 2 ). Now consider T ( n ) : T ( n ) 2 c ( n/ 4) lg( n/ 4) + c ( n/...
View
Full
Document
This note was uploaded on 01/20/2012 for the course CS 6.006 taught by Professor Erikdemaine during the Fall '08 term at MIT.
 Fall '08
 ErikDemaine
 Algorithms

Click to edit the document details