1 / 27

CSCI2110 – Discrete Mathematics Tutorial 7 Solving Recurrence

CSCI2110 – Discrete Mathematics Tutorial 7 Solving Recurrence. Wong Chung Hoi (Hollis) chwong@cse.cuhk.edu.hk 19-10-2011. Agenda. How to solve recurrence? Solving Second order linear homogeneous recurrence Fibonacci Series Counting Rabbits (Revisit) Counting Strings (Revisit)

loki
Download Presentation

CSCI2110 – Discrete Mathematics Tutorial 7 Solving Recurrence

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSCI2110 – Discrete MathematicsTutorial 7Solving Recurrence Wong Chung Hoi (Hollis) chwong@cse.cuhk.edu.hk 19-10-2011

  2. Agenda • How to solve recurrence? • Solving Second order linear homogeneous recurrence • Fibonacci Series • Counting Rabbits (Revisit) • Counting Strings (Revisit) • Gambler’s Ruin

  3. How to solve recurrence? • By iteration • By guessing / observation • For second order linear homogenous recurrence • By Distinct Roots Theorem • By Single Root Theorem

  4. Second Order Linear Homogeneous Recurrence • The format: ak = Aak-1 + Bak-2 • Second Order • ak depends on ak-1, ak-2, but not ak-3, ak-4, or k etc • Linear • ak-1, ak-2 has degree 1 • Homogeneous • All terms has the same degree, i.e. no constant term

  5. Second Order Linear Homogenous Recurrence? • ak = 3ak-2 • ak = 2ak-2 + 3ak-3 • ak = 3ak-1 + 2 • ak = 4ak-12+4ak-22 • ak = 93ak-1 + 10-2ak-2 • ak = ak-1 + k • ak = a1ak-1 + a2ak-2, a1 = 1, a2 = 2

  6. Solving Second Order Linear Homogenous Recurrence • To solve: ak = Aak-1 + Bak-2, a1 = C, a2 = D Solve the characteristic equation t2 – At – B = 0 t has 2 roots? t has single root? Single-Root Theorem an = Ern + Fnrn Distinct-Roots Theorem an = Ern + Fsn Solve E, F by a1, a2

  7. Solving Characteristic Equation The characteristic equation for recurrence an = Aan-1 + Ban-2 is given by t2 – At – B = 0 Exercise: Solve for t in terms of A and B.

  8. Distinct-Roots Theorem If the characteristic equation t2 - At - B = 0 has 2 distinct roots s, r for t. Then, the closed form of an is given by an = Ern + Fsn Exercise: With the assumption when n = k-2, k-1, closed form an = Ern + Fsn is equivalent to recurrence an = Aan-1 + Ban-2, show that when n = k, they are equivalent.

  9. Single-Root Theorem If the characteristic equation t2 - At - B = 0 has only single root r for t. Then, the closed form of an is given by an = Ern + Fnrn Exercise: Show that A = -2r, B = r2. With the assumption when n = k-2, k-1, closed form an = Ern + Fnrn is equivalent to recurrence an = Aan-1 + Ban-2, show that when n = k, they are equivalent.

  10. Solving E, F With boundary values a1 = C, a2 = D solve E,F by C = Er + Fs, D = Er2 + Fs2 for distinct roots C = Er + Fr, D = Er2 + F2r2 for single root

  11. Agenda • How to solve recurrence? • Solving Second order linear homogeneous recurrence • Fibonacci Series • Counting Rabbits (Revisit) • Counting Strings (Revisit) • Gambler’s Ruin

  12. Fibonacci Series • an = an-1 + an-2, a0 = 1, a1 = 1 • Characteristic equation t2 – t - 1 = 0 t = (1+51/2)/2 or (1-51/2)/2 • Distinct roots theorem an = E ((1+51/2)/2)n + F ((1-51/2)/2)n • Solving E, F by a0, a1 1 = E + F 1 = E (1+51/2)/2+ F (1-51/2)/2 E = (51/2 + 1) / (2 x 51/2) F = (51/2 - 1) / (2 x 51/2) an = 5-1/2 x((1+51/2)/2)n+1 – 5-1/2 x ((1-51/2)/2)n+1

  13. Fibonacci Series • an = an-1 + an-2, a0 = 2, a1 = 4 • Characteristic equation t2 – t - 1 = 0 t = (1+51/2)/2 or (1-51/2)/2 • Distinct roots theorem an = E ((1+51/2)/2)n + F ((1-51/2)/2)n • Solving E, F by a0, a1 2 = E + F 4 = E (1+51/2)/2+ F (1-51/2)/2 E = (51/2 + 3) / 51/2 F = (51/2 - 3) / 51/2 an = (1+ 3/51/2) ((1+51/2)/2)n + (1 – 3/51/2) ((1-51/2)/2)n

  14. Agenda • How to solve recurrence? • Solving Second order linear homogeneous recurrence • Fibonacci Series • Counting Rabbits (Revisit) • Counting Strings (Revisit) • Gambler’s Ruin

  15. Counting Rabbits - Revisit • Problem • Start with 1 pair of baby rabbit. • Rabbits take 2 months to become an adult. • Adult rabbits gives birth to 3 pairs of baby rabbits every month. • Rabbits NEVER DIE! • Number of pairs of rabbits in the end of the year? • Denote Rn as the number of rabbit after n month. • R0 = 1, R1 = 1, R2 = 1, R3 = 4, R4 = 7 • Rn = 3Rn-3 + Rn-1

  16. Counting Rabbits - Revisit • Problem • Start with 1 pair of baby rabbit. • Rabbits take 1 months to become an adult. • Adult rabbits gives birth to 3 pairs of baby rabbits every month. • Rabbits NEVER DIE! • Number of pairs of rabbits in the end of the year? • Denote Rn as the number of rabbit after n month. • R0 = 1, R1 = 1, R2 = 4, R3 = 7 • Rn = 3Rn-2 + Rn-1

  17. Counting Rabbits - Revisit • Finding the closed form: • Characteristic equation t2 – t – 3 = 0 t = (1-131/2)/2 or (1+131/2)/2 • Distinct-Roots Theorem Rn = E((1-131/2)/2)n + F((1+131/2)/2)n • Solve E, F by R0, R1 1 = E + F 1 = E(1-131/2)/2 + F(1+131/2)/2 E = (131/2 - 1) / (2 x 131/2) F = (131/2 + 1) / (2 x 131/2)

  18. Agenda • How to solve recurrence? • Solving Second order linear homogeneous recurrence • Fibonacci Series • Counting Rabbits (Revisit) • Counting Strings (Revisit) • Gambler’s Ruin

  19. Counting Strings - Revisit • Problem • A string made of 3 types of alphabets “a”, “b”, “c” • Count the number of string with length n and without the pattern “aa” • Let Ln be the number of string with length n and without pattern “aa” • L1 = 3, L2 = 8, L3 = 22… • Ln = 2Ln-1 + 2Ln-2,

  20. Counting Strings - Revisit Find the closed form for Ln = 2Ln-1 + 2Ln-2 • Characteristic Equation t2 – 2t – 2 = 0 t = 1 + 31/2, or 1 – 31/2 • By distinct roots theorem Ln = E(1+31/2)n + F(1-31/2)n • Solve E,F by L1, L2 3 = E(1+31/2) + F(1-31/2) 8 = E(1+31/2)2 + F(1-31/2)2 E = ? F = ?

  21. Counting Strings - Revisit • Solve E,F by L1, L2 3 = E(1+31/2) + F(1-31/2) 8 = E(1+31/2)2 + F(1-31/2)2 This is too complicated! Trick: What if L0 is part of our sequence? L2 = 2L1 + 2L0 → 8 = 2 x 3 + 2 L0 → L0 = 1 Solve E,F by L0, L1 1 = E + F 3 = E(1+31/2) + F(1-31/2) Exercise: Show that Ln = [(31/2+2)(1+31/2)n + (31/2 - 2)(1-31/2)n] / (2 x 31/2)

  22. Agenda • How to solve recurrence? • Solving Second order linear homogeneous recurrence • Fibonacci Series • Counting Rabbits (Revisit) • Counting Strings (Revisit) • Gambler’s Ruin

  23. Gambler’s Ruin • Problem: • Betting $1 on the outcome of a die until he has $300. • +$1 if he won, -$1 if he lost. • Probability that the gambler is ruined when he begin with $n? • Let Pn be the probability when he begin with $n. • P0 = 1, P300 = 0 • Recurrence equation: Pn-1 = 1/6 x Pn + 5/6 x Pn-2

  24. Gambler’s Ruin • Finding the closed form: • Characteristic equation: t2 - 6t + 5 = 0 t = 1 or 5 • Distinct-Roots Theorem Pn = E + F5n • Solve E, F by P0, P300 1 = E + F 0 = E + F5300 E = 5300 / (5300 - 1) F = 1/(1- 5300) Pn = (5300 – 5n) / (5300-1) • Exercise: Verify the closed form.Exercise: Approximate P20.

  25. Gambler’s Ruin 2 • Problem: • Betting $1 on the outcome of a coin until he has $300. • +$1 if he won, -$1 if he lost. • Probability that the gambler is ruined when he begin with $n? • Let Pn be the probability when he begin with $n. • P0 = 1, P300 = 0 • Recurrence equation: Pn-1 = 1/2 x Pn + 1/2 x Pn-2

  26. Gambler’s Ruin 2 • Finding the closed form: • Characteristic equation: t2 - 2t + 1 = 0 t = 1 • Single-Root Theorem Pn = E1n + Fn1n • Solve E, F by P0, P300 1 = E 0 = E + 300F E = 1 F = -1/300 Pn = 1-n/300 • Exercise: Verify the closed form.Exercise: CalculateP20.

  27. Summary • Ways of solving recurrence • Iteration, guessing / observing • What is Second order linear homogenous recurrence? • How to solve?

More Related