Recurrence Relations

 

How we will proceed

•      1. A definition of recurrence relations.

–    A recurrence relationship is a rule by which a sequence is generated.

•      2. Given the initial condition and the rule (i.e. the recurrence relations) what is the sequence?

•      3. Given the rule and a sequence, is the sequence a solution of the recurrence relations?

•      Facts about recurrence relations

•      Modeling problems with recurrence relations

 

Definition of a recurrence relation

•      A recurrence relation for the sequence {an} is an equation that expresses an in terms of one or more of the previous terms of the sequence.

–    an is the next term in the sequence

•      The sequence {an} looks like this:  a0, a1, …an-1

–    For all integers n with n >=  n0, where n0 is a nonnegative integer

•      A sequence is called a solution of a recurrence relation if its terms satisfy the recurrence relation.

 

Given the recurrence relation and initial condition, find the sequence

•      Let {an} be a sequence that satisfies the recurrence relation

–     Rule: an = a n-1 – a n-2

–   Initial conditions:  a0 = 3 and a1 = 5

–   What is the sequence?

 

 Given the rule and a sequence, is the sequence a solution of the recurrence relations?

•       Rule: an = 2a n-1 – a n-2

•      Sequence: an = 3n

•      Two ways to solve

–   Figure out the sequence, and see if it satisfies the rule

    the sequence is: a0= 0, a1=3, a2=6, a3=9, a4 = 12

      at n = 4: a4 ?= 2a3 – a2
                       12  ?=  2(9) - 6

–   Substitute 3n for n in the rule and simplify
2a n-1 – a n-2 = 2[3(n-1)] – 3(n-2)
 
when simplified, the does indeed = 3a

 

Given the rule and a sequence, is the sequence a solution of the recurrence relations?

•       Rule: an = 2a n-1 – a n-2

•      Sequence: an = 2n

•      The sequence is:
  
a0= 1, a1=2, a2=4, a3=8, a4 = 16

 

•      Does this fit the rule?

•       At n=4:   a4 ?= 2a3 – a2

      16 ?= (2*8) – 4

•      So an = 2n  is not a solution

 

Facts about recurrence relations

•      The recurrence relation and initial conditions uniquely determine a sequence

•      Any term of the sequence can be found from the initial conditions using the recurrence relation a sufficient number of times

•      But, for a certain class of sequences defined by a recurrence relation and initial condition there are better ways to find any term

 

Overheads

 

Modeling rabbits

•      A young pair of rabbits is placed on an island.  After they are two months old, each pair of rabbits produces another pair each month.  Find a recurrence relation for the number of pairs of rabbits on the island after 6 months.  After n months.  (Assume no rabbits die.)

 

Towers of Hanoi

•      There are three pegs and disks of different sizes. 

•      The object is to move all the disks from one peg to another

•      The Rules

–    One disk is moved at a time

–    A disk may not be placed on top of a disk  of smaller diameter

•      Let Hn denote the number of moves needed to solve with n disks. 

•      Set up a recurrence relation for the sequence {Hn}

 

Recurrence relation for Towers of Hanoi

•      What is the initial condition H1?

–   I.e. how many moves to move one disk?

•      We want to develop a rule to tell us how many moves it will take to move n disks in terms of moving n-1 disks

 

Counting bit strings

•      Find a recurrence relation and give initial conditions for the number of bit strings of length n that do not have two consecutive 0s.

•      a1 = num valid bit strings of length 1
 {a1} is 0, 1

•       a2 = num valid bit strings of length 2
  {a2} is 01, 10, 11

•      a3 = num valid bit strings of length 3
  {a3} is  010, 011, 101, 110, 111

•      By the sum rule, the total number of bit strings of length n without two consecutive 0 bits is equal to the number ending with 0 plus the number ending with 1

What is the sum rule?

•If a first task can be done in n1 ways and a second task in n2 ways, and if these tasks cannot be done at the same time, then there are n1 + n2 ways to do either task

 

Using the sum rule

•      Assume n >= 3

•      How many strings of length n are there ending with 1?

–   It’s all the strings in {an-1} with a 1 added

•      How many strings of length n are there ending with a 0?

–   It’s all the strings in {an-2} with a 10 added

•      What is {a3} given {a2} and {a1}?

•What is {a4}?

 

How many code words are valid?

•      A decimal digit code word is valid if it contains an even number of 0 digits

•      Find a recurrence relation for an, the number of valid code words of length n

•       What is the initial condition (n=1):  a1

–   What is {a1}

–   {a1} = 1,2,3,4,5,6,7,8,9,  so a1 = 9

•How can we form valid strings of length n using strings of length n-1?

 

Forming strings of length n

•      Two ways to form a valid string of n digits from a string of n-1 digits

•      First way

–    Append anything but a 0 to a valid string of n-1 digits

–    How many strings does this give us?

•     9 * an-1

•      Second way

–    Add a zero to an invalid string of length (n-1)

–    How many invalid strings of length (n-1)

•    (Total number of strings ) – (number of valid strings)
      10n-1                             -  an-1

•Add first way and second way
  9an-1 + (10n-1 – an-1)  or     8an-1 + 10n-1

 

How many cars produced?

•      A factory makes custom sports cars at an increasing rate.  In the first month only one car  is made, in the second month two cars are made, and so on, with n cars made in the nth month.

•      Set up a recurrence relation for the number of cars produced in the first n months by this factory.

•      How many cars are produced in the first year?

•      Find an explicit formula for the number of cars produced in the first n months by this factory.

–    An explicit formula is one that used the initial condition rather than the previous term.

•      Let Cn = the total number of cars produced in the first n months

•      Look on page 76 in Rosen for a table of some useful summation formulae.

 

Solving recurrence relations

•      We will work on linear homogeneous recurrence relations of degree k with constant coefficients. 

•      Its form is: an = c1an-1 + c2an-2 + …+ ckan-k  where c1, c2, …ck are real numbers, and ck != 0

•      This is linear since the right hand side is a sum of the multiples of the previous terms

•      It is homogeneous since all the terms are multiples of a

•      All of the coefficients are constant, rather than depend on n.

•      The degree is k because an is expressed in terms of the previous k terms of the sequence

 

The degree of a recurrence relation

•      Pn = (11.1)Pn-1  is degree one

•      fn = fn-1 + fn-2 is degree two

•      what is this?  Cn = Cn-5?

•      The basic approach to solving these type of problems is to look for solutions of the form an = rn

Linear homogeneous recurrence relations of degree 2

•       Let c1 and c2 be real numbers.  Suppose that
 r2 – c1r – c2 has two distinct roots r1 and r2

•      Then the sequence {an} is a solution of the recurrence relation an = c1a n-1 + c2a n-2 if and only if an = "1 r1n  + "2 r2n      for n = 0, 1,2,…where "1 and "2 are constants.

•      Look at a real problem:       

–    What is the solution of the recurrence relation:
an = a n-1 + 2a n-2 with a0 = 2 and a1 = 7



Solving linear homogeneous recurrence relations of degree 2

•       First, get the constants C1 and C2

•      Next, write the characteristic equation

•      Then find the roots

•      Find "1 and "2 , usually by solving simultaneous equations and using initial conditions