280 likes | 644 Views
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
E N D
CSCI2110 Tutorial 8:Solving Recurrence Chow Chi Wang (cwchow ‘at’ cse.cuhk.edu.hk)
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
Solving recurrence by iteration • Consider this recurrence relation: , and • How do we solve this?
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)
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. ).
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.
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 .
Second Order Recurrence second order linear homogeneous recurrence relation with constant coefficients • Constant coefficients means that both and are constants.
Second Order Recurrence • Which of following recurrence relations are second order linear homogeneous recurrence with constant coefficients?
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
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
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 .
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.
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.
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 .
Counting Strings - Revisit • The recurrence relation is given by: . • And the initial conditions are . • Using the initial conditions, we have: • So we have .
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.
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.
Gambler’s Ruin • The gambler guesses the correct outcome of a die with probability , so we have: for • And the boundary conditions are .
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 .
Gambler’s Ruin • The recurrence relation is given by: • And the boundary conditions are. • Using the boundary conditions, we have: • So we have .
Gambler’s Ruin • The recurrence relation is given by: • And the boundary conditions are. • Therefore:
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: .
Exercise • Solve the following recurrence: • for . • for . • for .
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.