recurrence relation

RECURRENCE
1.
2.
3.
Sequence
Recursively defined sequence
Finding an explicit formula for
recurrence relation
1
Learning Outcomes

You should be able to solve
first-order and second-order linear
homogeneous recurrence relation with
constant coefficients
2
Preamble

What is recurrence and how does it
relate to a sequence?
3
Sequences

A sequence is an ordered list of objects (or events). Like a set,
it contains members (also called terms)
Sequences can be finite or infinite.

2,4,6,8,…

for i ≥ 1
ai = 2i (explicit formula)
infinite sequence with infinite distinct values

-1,1,-1,1,…
for i ≥ 1
bi = (-1)i
infinite sequence with finite distinct values

For
1<=i<=6
ci = i+5
finite sequence (with finite distinct values)
6,7,8,9,10,11
4
Ways to define sequence




Write the first few terms:
3,5,7,…
Use explicit formula for its nth term
an = 2n for n ≥ 1
Use recursion
How to define a sequence using a
recursion?
5
Recursively defined sequences
Recursion can be used to defined a sequence.
This requires:
A recurrence relation: a formula that relates each term ak
to some previous terms ak-1, ak-2, …
ak = ak-1 + 2ak-2
The initial conditions: the values of the first few terms a0, a1, …
Example: For all integers k ≥ 2, find the terms b2, b3 and b4:
bk = bk-1 + bk-2 (recurrence relation)
b0 = 1 and b1 = 3 (initial conditions)
Solution:
b2 = b1 + b0 = 3 + 1 = 4
b3 = b2 + b1 = 4 + 3 = 7
b4 = b3 + b2 = 7 + 4 = 11
6
Explicit formula and
recurrence relation

Show that the sequence 1,-1!,2!,-3!,4!,…,(-1)nn!,…
for n≥0, satisfies the recurrence relation
sk = (-k)sk-1 for all integers k≥1.
The general term of the sequence: sn=(-1)nn!
substitute k and k-1 for n to get
sk=(-1)kk! sk-1=(-1)k-1(k-1)!
Substitute sk-1 into recurrence relation:
(-k)sk-1 = (-k)(-1)k-1(k-1)!
= (-1)k(-1)k-1(k-1)!
= (-1)(-1)k-1 k(k-1)!
= (-1)k k! = sk
7
Examples of recursively
sequence
Famous recurrences
Arithmetic sequences: ak = ak-1 + d
e.g. 1,4,7,10,13,…
geometric sequences: ak = ark-1
e.g. 1,3,9,27,…
Factorial: f(n) = n . f(n-1)
Fibonacci numbers: fk = fk-1+fk-2
1,1,2,3,5,8,…
Tower of Hanoi problem

8
Tower of Hanoi
9
10
11
12
Application of recurrence

Analysis of algorithm containing recursive function such as
factorial function.
Algorithm f(n)
/input: A nonnegative integer
/output: The value of n!
If n = 0 return 1
else return f(n-1)*n


No. of operations (multiplication) determines the efficiency of
algo.
Recurrence relation is used to express the no. of operation in
the algorithm.
13
Solving Recurrence relation by
Iteration



It is helpful to know an explicit formula for a
sequence.
An explicit formula is called a solution to the
recurrence relation
Most basic method is iteration
- start from the initial condition
- calculate successive terms until a pattern
can be seen
- guess an explicit formula
14
Some examples
Let a0,a1,a2,… be the sequence defined recursively as follows: For
all integers k≥1,
(1) ak = ak-1+2
(2) a0 = 1
Use iteration to guess an explicit formula for the sequence.
a0=1
a1=a0+2
a2=a1+2=(1+2)+2 = 1+2.2
a3=a2+2=(1+2.2)+2 = 1+3.2
a4=a3+2=(1+3.2)+2 = 1+4.3
….
Guess: an=1+n.2=1+2n
The above sequence is an arithmetic sequence.
15
Geometric Sequence
Let r be a fixed nonzero constant, and suppose a sequence
a0,a1,a2,… is defined as follows:
ak = rak-1 for all integers k ≥ 1
a0 = a
Use iteration to guess an explicit formula for the sequence
a0=a
a1=ra0=ra
a2=ra1=r(ra)=r2a
a3=ra2=r(r2a)=r3a
Guess: an=rna = arn for all integers n≥0
The above sequence is geometric sequence and r is a common
ratio.
16
17
Explicit formula for tower of Hanoi





mn = 2n – 1. (exponential order)
To move 1 disk takes 1 second
m64 = 264 –1 = 1.844674 * 1019 seconds
= 5.84542 * 1011 years
= 584.5 billion years.
18
Second-Order Linear Homogeneous with
constant coefficients

A second-order linear homogeneous
recur. relation with c.c. is a recur.
relation of the form
ak = Aak-1 + Bak-2 for all integers k ≥
some fixed integer,
where A and B are fixed real numbers
with B ≠ 0.
19
Terminology





ak = Aak-1 + Bak-2
Second order: ak contains the two previous
terms
Linear: ak-1 and ak-2 appear in separate terms
and to the first power
Homogeneous: total degree of each term is
the same (no constant term)
Constant coefficients: A and B are fixed real
numbers
20
Examples






Second-Order Linear Homogeneous with constant
coefficients
ak = 3ak-1 + 2ak-2 - yes.
bk = bk-1 + bk-2 + bk-3 - no
dk = (dk-1)2 + dk-1dk-2 - no; not linear
ek = 2ek-2 - yes; A = 0, B = 2.
fk = 2fk-1 + 1 - no; not homogeneous
21
Characteristic equation
a = Aak-1 + Bak-2 for k>=2 ….. (1)
Suppose that sequence 1, t, t2, t3,… satisfies relation (1) where t is
a nonzero real number.
General term for the sequence an=tn.
Hence, ak-1=tk-1 and ak-2= tk-2
Substitute ak-1 and ak-2 into relation (1)
tk = Atk-1 + Btk-2
Divide the equation by tk-2:
t2 = At + B or t2 – At – B = 0
This equation is called the characteristic equation of the
relation.
Recurrence relation (1) is satisfied by the sequence 1,t,t2,t3,… iff t
satisfies the characteristic equation.
 k
22
Using the characteristic equation to
find sequences
Example: Consider the following recurrence relation
ak = ak-1+2ak-2 for all k >= 2.
Find sequences that satisfy the relation.
Solution: For the given relation, A=1 and B=2.
Relation is satisfied by the sequence 1,t,t2,t3,… iff t satisfies the
characteristic equation
t2 – At – B = 0 or
t2 – t – 2 = 0
(t – 2)(t + 1) = 0.
t = 2 or t = -1.
Sequences: 1,2,22,23,… and
1,-1,(-1)2,(-1)3, … or 1,-1,1,-1, …,(-1)n, …

23
Linear combination of
sequences
Lemma
If r0,r1,r2,…,rn,.. and s0,s1,s2,…,sn,… are sequences that
satisfy the same second-order linear homogeneous
recurrence relation with c.c., and if C and D are any
numbers, then the sequence a0,a1,a2,…
defined by the formula
an = C.rn + D.sn for all integer n>=0
also satisfies the same recurrence relation.
 C and D can be calculated using initial conditions.

24
Two possible solutions

For the characteristic equation
t2 – At – B = 0
there are two possible solutions:
- Distinct-roots case
- Single-root case
25
Explicit formula for second-order
relation – Distinct-roots case
Find a sequence (explicit formula) that satisfies the
recurrence relation
ak=ak-1 + 2ak-2 for k>=2
and initial conditions
a0=1 and a1=8
Solution:
A=1 and B=2.
Characteristic equation : t2 – At – B =0
Substitute A and B, t2 – t – 2 = 0
Sequences: 1,2,22,23,… and
1,-1,1,-1, …,(-1)n, …

26
27
Steps for finding explicit
formula
1. Form the characteristic equation.
2. Solve the equation – let r and s be the
roots. ( r ≠ s)
3. Set up an explicit formula:
ak = C.rk + D.sk
4. Find C and D using initial conditions.
28
Quadratic equation


ax2 + bx + c = 0
x = [-b +- √(b2 – 4.a.c)]/(2.a)
29
30
31
32
Single-Root Case

Two sequences that satisfy the relation
ak = A.ak-1+B.ak-2
where r is the root of t2 - A.t - B = 0.
Explicit formula for the new sequence
an = C.rn + D.nrn
33
Example
A sequence b0, b1, b2,… satisfies the rec. relation
bk = 4bk-1 – 4bk-2 for k>=2 with initial conditions b0=1
and b1=3.
Find explicit formula for the sequence.
Solution: A=4 and B=-4
Charac eq: t2 – 4t +4 =0
(t-2)2=0. t=2.
Seq: 1,2,22, …, 2n,..
0,2,2.22,3.23,…,n.2n,…
Explicit formula: bn = C.rn + D.nrn
= C.2n + D.n2n
34

Example








bn = C.2n + D.n2n
b0 = 1 = C.20 + D.0.20 = C
b1 = 3 = C.2 + D.2
3 = 1.2 + 2D
Hence D = ½.
Therefore bn = 2n + (1/2).n.2n
= 2n (1+ n/2) for integer n>=0.
Sequence: 1,3,8,20,…
35
Question
?????
36
Summary



How to express the sequence
Find explicit formula for first-order
recurrence relation
Find explicit formula for second-order
recurrence relation (distinct and single
root)
37
THANK YOU
38