P1. Solve the recurrence relation withoutusing Master’s theorem: T(N) = 3T(N/2) + cN Ans.: Assume N = 2kT(2k) = 3 T(2k-1) + c 2k= 32T(2k-2) + c ( 2k+ 3* 2k-1) …. After k steps = 3kT(1) + c ( 2k+ 3* 2k-1+ 32* 2k-2+ … + 3k-1* 2) = 3kd + c 2k(1 + 3/2 + (3/2)2+ (3/2)3+ …. + (3/2)k-1) = 3kd + c N [ (3/2)k–1] / [3/2 –1] = 3kd + 2c N ( 3k/N – 1) = 3k(d + 2c) – 2cN Now, 3k= (2 log 3) k= (2 k )log 3= N log 3= N log 3(2c + d) – 2cN = Theta (N log 3) P2. Aand Bare playing a guessing game where Bfirst thinks up an integer X(positive, negative or zero, and could be of arbitrarily large magnitude) and Atries to guess it. In response to A’s guess, Bgives 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 Ahas 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
This preview has intentionally blurred sections.
Sign up to view the full version.