{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# sol2 - 1[10 marks(a We obtain the recurrence T(n = 8T = 8T...

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

1. [10 marks] (a) We obtain the recurrence T ( n ) = 8 T p n 3 P + 5 p n 3 P 2 = 8 T p n 3 P + 5 p n 2 9 P Thus, we have a = 8, b = 3 and f ( n ) = 5 p n 2 9 P . As log b a = log 3 8 < 2, we have f ( n ) = 5 ± n 2 9 ² = Ω( n log 3 8+ ǫ ) = Ω( n log b a + ǫ ) for some ǫ > 0. Thus, it follows from the Master theorem that T ( n ) = Θ( f ( n )) = Θ( n 2 ) . This would be better than Strassen’s algorithm. (b) For the recurrence T ( n ) = 4 T ³ 2 n 3 ´ + n 2 we have a = 4 and b = 3 / 2. As log b a = log 3 / 2 4 > 2, we have f ( n ) = n 2 = O ( n log 3 / 2 4 ǫ ) = O ( n log b a ǫ ) for some ǫ > 0. Thus, it follows from the Master theorem that T ( n ) = Θ( n log b a ) = Θ( n log 3 / 2 4 ) . (c) For the recurrence T ( n ) = 4 T ³ n 2 ´ + n 2 we have a = 4 and b = 2. As log b a = log 2 4 = 2, we have f ( n ) = n 2 = Θ( n log 2 4 ) = Θ( n log b a log 0 n ) . Thus, it follows from the Master theorem that T ( n ) = Θ( n log b a log n ) = Θ( n 2 log n ) . 2. [10 marks] For integers 1 to n there are n! permutations. Most of them require log n ! = n log n cn bits to encode, where c is some constant. Fix one such permutation π such that C ( π ) n log n cn (1)

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

View Full Document
Let f ( j ) be the number of swaps applied to the element A [ j ] at the j -th step. Then given the f ( j )’s, one can infer the original permutation π by running the Bubble Sort in reverse (loop from Fnal item that reaches the correct position to the Frst item, reversing the swaps for each item according to the appropriate value of f ( j )). This implies that we can use: Σ n j =1 log f ( j ) (2) bits to encode π . ±rom equation (1) we get that Σ n j =1 log f ( j ) n log n cn . The running time of bubble sort on the input π is Σ n j =1 f ( j ). When the f ( j )’s are all equal, (2) is maximized and n log f ( j ) n log n cn for some c . So f ( j ) n c for some appropriate c that depends on c . Applying this to (3) we get that the running time on average input must be Ω( n 2 ). Since bubble sort is already known to be O ( n 2 ) in the worst case (which the average case cannot be worse than), we have the required Θ( n 2 ) bound for the average case. 3. [10 marks] Let A ( x ) = a n x n + a n 1 x n 1 + . . . + a 1 x + a 0 and B ( x ) = b m x m + b n 1 x n 1 + . . . + b 1 x + b 0 be two polynomials. We can store these by storing their coe²cients in arrays A [ n ] and B [ m ]. Thus, in order to compute the product C ( x ) = A ( x ) B ( x ) we need to compute the coe²cients c 0 , . . . , c n + m and store them in an array C [ n + m ]. (a) Let A ( x ) = a 1 x + a 0 and B ( x ) = b 1 x + b 0 be two linear polynomials. We know that C ( x ) = A ( x ) B ( x ) = a 1 b 1 x 2 + ( a 1 b 0 + a 0 b 1 ) x + a 0 b 0 If we compute ( a 1 + a 0 )( b 1 + b 0 ) = a 1 b 1 + a 1 b 0 + a 0 b 1 + a 0 b 0 we have c 2 = a 1 b 1 c 1 = ( a 1 + a 0 )( b 1 + b 0 ) a 1 b 1 a 0 b 0 c 0 = a 0 b 0 Thus, we can compute the product of two linear polynomials with only three multiplications. (b) We let n be the maximum degree of A ( x ) and B ( x ). We can then assume that both polynomials are of degree n (by Flling up the array for the lower degree polynomial with an appropriate number of zeros). ±or simplicity, we will also assume that n is a power of 2 (by the same reasoning). Then we have A ( x ) = x n 2 ( a n x n 2 + a n 1 x n 2 1 + . . . + a n 2 +1 x ) + ( a n 2 x n 2 + a n 2 1 x n 2 1 + . . . + a 0 ) = x n 2 A 1 ( x ) + A 0 ( x ) 2
where A 1 ( x ) and A 0 ( x ) are two polynomials of degree at most n 2 . Similarly we

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 ]}

### Page1 / 7

sol2 - 1[10 marks(a We obtain the recurrence T(n = 8T = 8T...

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

View Full Document
Ask a homework question - tutors are online