130 likes | 244 Views
CS 427 Practice Problems for Assignment # 2. Appendix B: #1 b,c; 12 a,c; 20 (1a). # 1.b. Use induction to verify the candidate solution. t n = t n – 1 + 5 for n > 1 t 1 = 2 The candidate solution is t n = 5 n – 3. Basis Step: let n = 1 then
E N D
CS 427 Practice Problems for Assignment # 2. • Appendix B: #1 b,c; 12 a,c; 20 (1a)
# 1.b. Use induction to verify the candidate solution t n = t n – 1 + 5 for n > 1 t 1 = 2 The candidate solution is t n = 5n – 3. Basis Step: let n = 1 then t 1 = 5(1) – 3 t 1 = 2 Inductive Hypothesis: Assume that t n = 5n – 3 for n > 1 Inductive Step: We need to show that t n+1 = 5(n+1) – 3 Now use the recurrence equation for t n+1 t n+1 = t n + 5 Now substitute the candidate solution for t n
Inductive Step (continued): Now substitute the candidate solution for t n t n+1 = t n + 5 t n+1 = (5n – 3) + 5 t n+1 = (5n – 3) + 5 t n+1 = 5n – 3 + 5 t n+1 = 5n + 5 – 3 t n+1 = 5(n+1) – 3 Which is what we needed to show.
# 1.c. Use induction to verify the candidate solution t n = t n – 1 + n for n > 1 t 1 = 1 The candidate solution is t n = Basis Step: let n = 1 then t 1 = 2/2 1 as defined Inductive Hypothesis: Assume that t n = for n > 1 Inductive Step: Show that t n+1 = n(n+1) 2 1(1+1) 2 n(n+1) 2 (n+1)(n+2) 2
Inductive Step (continued): Use the recurrence equation for t n+1 t n+1 = t n + (n + 1) next substitute the characteristic equation for t n t n+1 = + (n + 1) + t n+1 = This is what we wanted to show. n(n+1) 2 n2 + n 2 2n +2 2 n2 + 3n + 2 2 (n+1)(n+2) 2
# 12.a. Solve the recurrence equations using the c.e. This is a homogeneous linear recurrence ( see p.469) t n = 4t n – 1 - 3t n – 2 for n > 1 t 0 = 0, t 1 = 1 Obtain the characteristic equation. t n - 4t n – 1 + 3t n – 2 = 0 t n = r n then we get r n - 4r n-1 + 3r n-2 = 0 then factor out r n-2 to getr n-2 (r 2 - 4r + 3) = 0 r = 0 is a root, but we need to find the nonzero roots. (r 2 - 4r + 3) = 0 (r – 3)(r – 1) = 0 so we have nonzero roots at 3 and 1. Roots = [3 1] Using these roots we see our general solution is t n = c1 3 n + c 2 1 n c1 3 n + c 2
Now we use our initial conditions to find the values of c1 and c 2 t n = c1 3 n + c 2 t 0 = 0 c1 3 0 + c 2 = 0 t 1 = 1 c1 3 1 + c 2 = 1 Now we have two equations and two unknowns. c1 + c 2 = 0 c 2 = - c 1 3c1 + c 2 = 1 next substitute 3c1 - c1 = 1 2c 1 = 1 c 1 = 1/2 c 2 = - ½ So the general solution with the correct coefficients is: t n = (1/2)3 n – 1/2
# 12.c. Solve the recurrence equations using the c.e. This is a non-homogeneous linear recurrence (p 477. Theorem B.3 on p 479) t n = 5t n – 1 - 6t n – 2 + 5 n for n > 1 t 0 = 0, t 1 = 1 First reorganize the recurrence equation. t n - 5t n – 1 + 6t n – 2 = 5n (1) Now use theorem B.3 to find the characteristic equation b = 5, p(n) = 1 so d = 0, k = 2 ( r k – 5r k-1 + 6r k-2 )(r – 5) 1 = 0 r k-2 ( r 2 – 5r + 6)(r – 5) = 0 Remember, we are looking for nonzero roots so… ( r 2 – 5r + 6)(r – 5) = 0 now factor ( r – 3 )( r – 2 )( r – 5) = 0 so the roots are [3 2 5]
The roots are [3 2 5] so we apply theorem B.1 to find the general solution: t n = c12 n + c23 n + c35 n Now we use the initial conditions to find the coefficients. t 0 = 0 = c12 0 + c23 0 + c35 0 t 1 = 1 = c12 1 + c231 + c35 1 Now there are two equations, but three unknowns so we need another initial condition. Use the recurrence to find t 2 t 2 = 5t 1 - 6t0 + 52 t 2 = 5(1) – 6(0) + 25 t 2 = 30 Now there are three equation and three unknowns. Solve. t 0 = 0 = c1 20 + c2 3 0 + c3 5 0 c1 + c2 + c3 = 0 t 1 = 1 = c1 21 + c2 31 + c3 5 1 2c1 + 3c2 + 5c3 = 1 t 2 = 30 = c1 22 + c2 32 + c3 52 4c1 + 9c2 + 25c3 = 30
You can solve for the unknowns c 1, c 2, and c 3 however you like. c 1 c 2 c 3 sum • 1 1 0 • 3 5 1 • 4 9 25 30 • 1 1 0 • 0 1 3 1 • 4 9 25 30 • 1 1 0 • 0 1 3 1 • 0 5 21 30 -2*row1 + row2 -4*row1 + row3 • 1 1 0 • 0 1 3 1 • 0 0 1 25/6 • 1 1 0 • 0 1 0 -23/2 • 0 0 1 25/6 • 1 1 0 • 0 1 3 1 • 0 0 6 25 -3*row3 + row2 -5*row2 + row3 (row3)/6 • 0 1 23/2 • 0 1 0 -23/2 • 0 0 1 25/6 • 0 0 22/3 • 0 1 0 -23/2 • 0 0 1 25/6 c1 = 22/3 c2 = -23/2 c3 = 25/6 -1*row2 + row1 -1*row3 + row1
c1 = 22/3 c2 = -23/2 c3 = 25/6 Remember the general solution with the unknowns: t n = c12 n + c23 n + c35 n Now replace the unknowns with the values we found: t n = (22/3)2 n + (-23/2)3 n + (25/6)5 n Now we are finished.
# 20 - 1.a. Solve the recurrence equations using the substitution method The substitution method is described on pages 486-487 t n = 4t n – 1 for n > 1 t 1 = 3 Use the recurrence equation to generate values from t n to t 1. t n = 4 t n-1 t n-1 = 4 t n-2 t n-2 = 4 t n-3 …... t 2 = 4 t 1 t 1 = 3
Next substitute each equation into the previous one. t n = 4 t n-1 = 41 t n-1 t n = 4 ( 4 t n-2)= 42 t n-2 t n = 4 ( 4 ( 4 t n-3))= 43 t n-3 t n = 4 (4 ( 4 ( 4 t n-4)))= 44 t n-4 …….. …….. t n = 4(4(4(4(….4 t2))))…)))= 4 n-2 t 2 t n = 4(4(4(4(4(….4 t1))))…)))) = 4 n-1 t 1 t 1 = 3 So… The general solution is: t n = 3( 4 n-1 )