Professional Documents
Culture Documents
Linear Recurrences
a0 , a1 , a2 , a3 , . . . , an , an+1 , . . .
fn = fn−1 + fn−2 , f0 = 0, f1 = 1.
To compute f2 , we have
f2 = f1 + f0 = 1.
To compute f3 , we have
f3 = f2 + f1 = 1 + 1 = 2.
We will see in this chapter two methods to solve linear recurrences in-
volving one or two preceding terms.
145
146 CHAPTER 6. LINEAR RECURRENCES
Recurrence Relation
A recurrence relation is an equation that recursively
defines a sequence, i.e., each term of the sequence is
defined as a function of the preceding terms
Fibonacci Sequence
Leonardo
Pisano Bigolio
(c. 1170-c.
1250)
Examples
• The Fibonacci sequence
• The relation: an=2an-1 (degree 1)
• But not the relation: an=2an-1+1
The characteristic equation of the above relation is
149
Theorem
If the characteristic equation x2-c1x-c2=0 (of the
recurrence relation an=c1an-1+c2an-2) has
• two distinct roots s1,s2, then the explicit formula
for the sequence an is
u.s1n+v.s2n
• a single root s, then the explicit formula for an is
u.sn+v.n.sn
where u & v are determined by initial conditions.
Example
Determine the number of bit strings (i.e., comprising
0/1s) of length n that contains no adjacent 0s.
• Cn = this number of bit strings
• A binary string with no adjacent 0s is constructed by
o Adding “1” to any string w of length n-1 satisfying the
condition, or
o Adding “10” to any string v of length n-2 satisfying the
condition
• Thus Cn = Cn-1 +Cn-2 where C1=2 (0,1), C2=3 (01, 10, 11)
151
This means that the final solution is really a composition of sn1 , sn2 , namely
a solution for an = c1 an−1 + c2 an−2 is given by
an = usn1 + vsn2 ,
where u, v depend on the initial conditions (that is on a0 , a1 ).
Suppose now that x2 − c1 x − c2 = 0 has one double real root s, that is
x − c1 x − c2 = (x − s)2 . Then
2
s2 − c1 s − c2 = 0,
and sn is a solution of an = c1 an−1 + c2 an−2 as for the case of two distinct
roots. We obtained the characteristic equation from
xn − c1 xn−1 − c2 xn−2 = xn−2 (x2 − c1 x − c2 ) = 0.
If s is a root of this equation, then s is a root of its derivative:
nxn−1 − c1 (n − 1)xn−2 − c2 (n − 2)xn−3 = 0.
Therefore s satisfies both
sn = c1 sn−1 + c2 sn−2 , nsn = c1 (n − 1)sn−1 + c2 (n − 2)sn−2 . (6.1)
If we combine sn and nsn , as we did for sn1 and sn2 , we get
an = usn + vnsn ,
and an+1 = usn+1 + v(n + 1)sn+1 . We are left to check
c1 an+1 + c2 an+2 = c1 (usn+1 + v(n + 1)sn+1 ) + c2 (usn+2 + v(n + 2)sn+2 )
= u[c1 sn+1 + c2 sn+2 ] + v[c1 (n + 1)sn+1 + c2 (n + 2)sn+2 ]
= usn+2 + v(n + 2)sn+2
= an+2
using (6.1), which is consistent with our recurrence relation.
Example 64. Suppose we want to determine the number of bit strings of
length n that contains no adjacent zeroes. We denote this number by Cn .
We first observe that there are two ways of obtaining such sequences from a
smaller sequence. One may take any string:
• of length n − 1 satisfying the condition and add a 1 (one cannot add a
0, since the sequence may finish by 0),
• of length n − 2 satisfying the condition and add 10 (one cannot add 00,
or 01 since the string could finish by 0, and 11 is included above).
152 CHAPTER 6. LINEAR RECURRENCES
Example
• Thus
Example
Initial conditions give us:
Solving, we get
153
Cn = Cn−1 + Cn−2 .
an = an−1 + 2an−2
with a0 = 2 and a1 = 7?
Exercise 53. Let an = c1 an−1 +c2 an−2 +. . .+ck an−k be a linear homogeneous
recurrence. Assume both sequences an , a0n satisfy this linear homogeneous
recurrence. Show that an + a0n and αan also satisfy it, for α some constant.
155
Tn = 2Tn−1 + 1,
Then
Tn = 2Tn−1 + 1
= 2(2Tn−2 + 1) = 4Tn−2 + 3
= 4(2Tn−3 + 1) + 3 = 8Tn−3 + 7
= 8(2Tn−4 + 1) + 7 = 16Tn−4 + 15
= ...
156 CHAPTER 6. LINEAR RECURRENCES
Hanoi Tower
• Goal: move all n disks in the
same order, but on a different
post.
• Only permitted action:
remove the top disk from a post
and drop it onto another post.
• Rule: a larger disk can never lie
above a smaller disk on any post.
Find a Recurrence
• 𝑇𝑛 = minimum number of steps needed to move an 𝑛-disk
tower from one post to another
𝑇𝑛 = 2𝑇𝑛−1 +1
𝑇𝑛−1
𝑇𝑛−1
Backtracking
𝑇1 = 1 𝑇𝑛 = 2𝑇𝑛−1 +1
158 CHAPTER 6. LINEAR RECURRENCES
Backtracking
𝑇1 = 1 𝑇𝑛 = 2𝑇𝑛−1 +1
𝑇𝑛
= 2𝑇𝑛−1 + 1 = 2 2𝑇𝑛−2 + 1 + 1 3
= 4𝑇𝑛−2 + 3 = 4 2𝑇𝑛−3 + 1 + 3 7
= 8𝑇𝑛−3 + 7 15
𝑇𝑛 = 2𝑛 − 1
Induction
• P(n)=``𝑇𝑛 = 2𝑛 − 1’’
• Basis step: P(1)=``𝑇1 = 1”
• Inductive step: suppose P(n) is true.
• To show, P(n+1).
• 𝑇𝑛+1 = 2𝑇𝑛 + 1 = 2 2𝑛 − 1 + 1 = 2𝑛+1 − 1
159
Tn = 2n−1 T1 + (2n−1 − 1)
as desired!
160 CHAPTER 6. LINEAR RECURRENCES