1 / 28

CSCI2110 Tutorial 8: Solving Recurrence

CSCI2110 Tutorial 8: Solving Recurrence. Chow Chi Wang ( cwchow ‘at’ cse.cuhk.edu.hk). Solving Recurrence. How to solve recurrence?. By iteration By guessing / observation For second order linear homogenous recurrence with constant coefficients By Distinct-Roots Theorem

bob
Download Presentation

CSCI2110 Tutorial 8: 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 Tutorial 8:Solving Recurrence Chow Chi Wang (cwchow ‘at’ cse.cuhk.edu.hk)

  2. Solving Recurrence

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

  4. Solving recurrence by iteration • Consider this recurrence relation: , and • How do we solve this?

  5. Solving recurrence by iteration

  6. Second Order Recurrence • You only need to know how to solve second order linear homogeneous recurrence relation with constant coefficients for this course. • It looks like: , where are constants and . • Concrete examples: • (the Fibonacci recurrence)

  7. Second Order Recurrence second order linear homogeneous recurrence relation with constant coefficients • Second Ordermeans that depends only on previous two terms . And it must depends on (i.e. ).

  8. Second Order Recurrence second orderlinear homogeneous recurrence relation with constant coefficients • Linear means that the sequence terms in the recurrence relation must be of degree 1. So we are not allowed to have something like etc. in our recurrence relation.

  9. Second Order Recurrence second order linear homogeneous recurrence relation with constant coefficients • Homogeneous means that the space of solutions is a linear space. In other words, the sum of any set of solutions or multiples of solutions is also a solution. • In our case, this simply means we don’t have the degree-0 term. So we are not allowed to have something this: , where .

  10. Second Order Recurrence second order linear homogeneous recurrence relation with constant coefficients • Constant coefficients means that both and are constants.

  11. Second Order Recurrence • Which of following recurrence relations are second order linear homogeneous recurrence with constant coefficients?

  12. Solving Second Order Recurrence • To solve : Step 1 Solve the corresponding characteristic equation: distinct roots ? single root ? By Distinct-Roots Theorem By Single-Root Theorem Step 2 Solve using

  13. Solving Second Order Recurrence (Step 1) • We have to solve the characteristic equation • You may use the quadratic formula: • The roots of the quadratic equation is given by

  14. Solving Second Order Recurrence (Step 2) • Depending on the root(s) we calculated in step 1: • if are distinct roots of the characteristic equation. • if is the repeated root of the characteristic equation. • We will use the initial conditions to determine the values of .

  15. Solving Second Order Recurrence (Step 2) • By substituting these conditions into the recurrence relation, we have: for the distinct root case. We can then determine the values of by solving this system of linear equations.

  16. Counting Strings - Revisit • The Problem • A string made of 3 types of alphabets “a”, “b”, “c” • Count the number of string with length and without the pattern “aa” • Let be the number of strings of length without the pattern “aa”. Find a recurrence relation and then solve it.

  17. Counting Strings - Revisit • The recurrence relation is given by: . • And the initial conditions are . • The characteristic equation is . • The roots of the equation are . • By the distinct roots theorem, we have: for some constants .

  18. Counting Strings - Revisit • The recurrence relation is given by: . • And the initial conditions are . • Using the initial conditions, we have: • So we have .

  19. Counting Strings - Revisit • The recurrence relation is given by: . • And the initial conditions are . • Therefore: • Tip: After finding the general formulae of the sequence, always remember to test it’s correctness by trying some base cases.

  20. 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 begins with $n? • Let be the probability that the gambler is ruined when he begins with $. Find a recurrence relation and then solve it.

  21. Gambler’s Ruin • The gambler guesses the correct outcome of a die with probability , so we have: for • And the boundary conditions are .

  22. Gambler’s Ruin • The recurrence relation is given by: • And the boundary conditions are. • The characteristic equation is . • The roots of the equation are or . • By the distinct roots theorem, we have: for some constants .

  23. Gambler’s Ruin • The recurrence relation is given by: • And the boundary conditions are. • Using the boundary conditions, we have: • So we have .

  24. Gambler’s Ruin • The recurrence relation is given by: • And the boundary conditions are. • Therefore:

  25. Gambler’s Ruin 2 • Problem: • Betting $1 on the outcome of a coinuntil he has $300. • +$1 if he won, -$1 if he lost. • Probability that the gambler is ruined when he begin with $n? • Let be the probability that the gambler is ruined when he begins with $. Find a recurrence relation and then solve it. • Answer: .

  26. Exercise • Solve the following recurrence: • for . • for . • for .

  27. Summary • You may solve simple recurrence by iteration, guessing / observing. • How to solve second order linear homogeneous recurrence with constant coefficients? (slide 12) • Tip: After finding the general formulae of the sequence, always remember to test it’s correctness by trying some base cases.

  28. Thank You!

More Related