{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2004_fall_exam1_sol - P1 Solve the recurrence relation...

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

View Full Document Right Arrow Icon
P1. Solve the recurrence relation without using Master’s theorem: T(N) = 3T(N/2) + cN Ans.: Assume N = 2 k T(2 k ) = 3 T(2 k-1 ) + c 2 k = 3 2 T(2 k-2 ) + c ( 2 k + 3* 2 k-1 ) …. After k steps = 3 k T(1) + c ( 2 k + 3* 2 k-1 + 3 2 * 2 k-2 + … + 3 k-1 * 2) = 3 k d + c 2 k (1 + 3/2 + (3/2) 2 + (3/2) 3 + …. + (3/2) k-1 ) = 3 k d + c N [ (3/2) k –1] / [3/2 –1] = 3 k d + 2c N ( 3 k /N – 1) = 3 k (d + 2c) – 2cN Now, 3 k = (2 log 3 ) k = (2 k ) log 3 = N log 3 = N log 3 (2c + d) – 2cN = Theta (N log 3 ) P2. A and B are playing a guessing game where B first thinks up an integer X (positive, negative or zero, and could be of arbitrarily large magnitude) and A tries to guess it. In response to A ’s guess, B gives exactly one of the following three replies: a) Try a bigger number b) Try a smaller number or c) You got it!! Design an efficient algorithm to minimize the number of guesses A has to make. An example (not necessarily an efficient one) below: B thinks up the number 35 A’s guess B’s response 10 Try a bigger number 20 Try a bigger number 30 Try a bigger number 40 Try a smaller number 35 You got it
Image of page 1

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

View Full Document Right Arrow Icon