hw3-sol - Solutions to Homework 3 Debasish Das EECS...

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

View Full Document Right Arrow Icon
Solutions to Homework 3 Debasish Das EECS Department, Northwestern University [email protected] 1 Problem 2.4 Recurrence for Algorithm A T ( n ) = 5 T ( n 2 ) + O ( n ) (1) Using Master’s theorem we get a bound of O( n log 5 ). Recurrence for Algorithm B T ( n ) = 2 T ( n - 1) + O (1) (2) The idea to solve such recurrence is to use a recursion tree and combine the constant time operation at each level of recursion tree. Alternatively you can use substitution. T ( n ) = 2 T ( n - 1) + O (1) T ( n - 1) = 2 T ( n - 2) + O (1) ... T (2) = 2 T (1) + O (1) Substituting the values of T(i-1) into the equation of T(i), we get the following sum T ( n ) = n - 1 X i =0 2 i · O (1) (3) Thus we obtain T(n) as O(2 n ) Recurrence for Algorithm C T ( n ) = 9 T ( n 3 ) + O ( n 2 ) (4) Using Master’s theorem we get O( n 2 log n ) If we do an order analysis, it turns out that Algorithm C is most efficient, since log n grows slower than n log 5 - 2 . 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Problem 2.12 In this problem we have to give an recurrence for the number of lines printed by the algorithm. The recurrence is given as follows L ( n ) = ± 1 + 2 L ( n 2 ) if n > 1 0 if n = 1 (5) Theorem 1 L(n) = Θ( n ) Proof: Base Case: L(1) = 0 which is Θ(1) Hypothesis: c 1 · k L(k) c 2 · (k-1), k < n Induction: L(n) = 1 + 2L( n 2 ) 1 + 2( c 1 · n 2 )=1+ c 1 n = k 1 n where k 1 is a constant equal to c 1 + 1 n Similarly for the other bound, L(n) = 1 + 2L( n 2 ) 1 + 2( c 2 · ( n 2 - 1)) = 1+ c 2 n - 2 c 2 = k 2 (n-1) where k 2 = c 2 - ( c 2 - 1) ( n - 1) Using above result we can say that L(n) is Θ( n ). We can do a more accurate analysis using recursion tree and establish that the line will be printed n-1 times, which is still Θ( n ). 3
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/15/2010 for the course COMPUTER S 6.657 taught by Professor Janelee during the Fall '08 term at Walden University.

Page1 / 5

hw3-sol - Solutions to Homework 3 Debasish Das EECS...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online