Mohamed G. Gouda CS 313K Fall 2012 Homework 5 1. Consider the recurrence equation: T(1) = 2 T(2) = 9 T(n+2) = 2*T(n+1) + 3*T(n) for n >= 1 Show, by induction, that T(n) =< 3^n for n >= 1 Sol: Let P(n) be the predicate T(n) =< 3^n. Base Case: n=1 and n=2: P(1) <=> T(1) =< 3 <=> 2 =< 3 <=> T P(2) <=> T(2) =< 9 <=> 9 =< 9 <=> T Induction Step: For n >= 1, P(n) and P(n+1) => P(n+2) T => {Definition of T(n+2)} T(n+2) = 2*T(n+1) + 3*T(n) => {Induction Hypothesis P(n) and P(n+1)} T(n+2) =< 2*(3^(n+1)) + 3*(3^n) = (2+1)*(3^(n+1)) = 3^(n+2) => {Definition of P(n+2)} P(n+2) 2. There are two ways to climb the steps of a stair: One step at a time and two steps at a time. Let T(n) denote the number of ways that can be used to climb n steps. Derive the recurrence equation for T(n). Sol: Clearly, T(1) = 1, T(2) = 2, T(3) = 3, T(4) = 5, ... The different ways to climb n steps are as follows: (1) First climb n-1 steps, using T(n-1) different ways, then climb the last step in one go. (2) First climb n-2 steps, using T(n-2) different ways, then climb the last two steps in one go. Therefore, T(n) = T(n-1) + T(n-2). Thus, the recurrence equation is: T(1) = 1 T(2) = 2 T(n+2) = T(n+1) + T(n) for n >= 1 3. Use the Characteristic Polynomial method to compute the closed equation for the following recurrence equation: T(0) = 5 (1) T(1) = 2 (2) T(n+2) = -10*T(n+1) - 25*T(n) for n >= 0 (3) Sol: The Characteristic Polynomial from (3) is: t^2 = -10*t - 25 t^2 + 10*t + 25 = 0 (t+5)^2 = 0 t1 = -5 and t2 = -5 Expression for T(n): T(n) = x*(-5)^n + y*n*(-5)^n (4) From (1) and (4): x = 5 (5) From (2), (4), and (5): 2 = 5*(-5) + y*(-5) y = -(27/5) (6) The closed equation from (4), (5), and (6): T(n) = 5*(-5)^n - (27/5)*n*(-5)^n 4. An amount of $10,000 is deposited in a savings account whose interest is 5% per year. How much money will be in the account after 30 years? Derive your answer. Sol: Let T(n) denote the amount of money in the account after 30 years. T(0) = 10,000 T(n+1) = (1.05)*T(n) Thus, T(1) = (1.05)*T(0) T(2) = (1.05)^2 * T(0) ... T(30) = (1.05)^(30) * T(0) = (1.05)^(30) * (10,000) = 43,219.42 Therefore, the account will have $43,219.42 after 30 years. 5. Show, by direct inference, that (f(x) is O(g(x))) and (g(x) is O(h(x))) => (f(x) is O(h(x))) Sol: (f(x) is O(g(x))) and (g(x) is O(h(x))) => {Definition of "O"} (All x > K1, |f(x)| =< C1*|g(x)|) and (All x > K2,|g(x)| =< C2*|h(x)|) => {Let K be max(K1,K2)} (All x > K, |f(x)| =< C1*|g(x)| and |g(x)| =< C2*|h(x)|) => {Arithmetics} (All x > K, |f(x)| =< C1*|g(x)| =< C1*C2*|h(x)|) => {Let C be C1*C2} (All x > K, |f(x)| =< C*|h(x)|) => {Definition of "O"} (f(x) is O(h(x))) 6. Show, by contradiction, that x^3 is not O(7 * x^2). Sol: x^3 is O(7 * x^2) => {Definition of "O"} (Exist C and K, (All x > K, |x^3| =< C*|7 * x^2|)) => {Arithmetics} (Exist C and K, (All x > K, |x| =< C*|7|)) => {Choose any value x' that is larger than max(K,C*7)} (Exist C and K, (All x > K, |x| =< C*|7|) and (Exist x' > K, |x'| > C*7)) => F