You are on page 1of 38

RECURRENCE RELATIONS Lecture No.

8
MATHEMATICAL MODELS, ANALYSIS TECHNIQUES
What is Recursion?
• Some times problems are too difficult or too
complex to solve because these are too big.
• A problem can be broken down into sub-
problems and find a way to solve these sub-
problems
• Then build up to a solution to the entire
problem.
• This is the idea behind recursion
• Recursive algorithms break down problem in
pieces which you either already know the
answer, or can be solved applying same
algorithm to each piece
• And finally combine the results of these sub-
problems to find the final solution
What is Recursion?

• More concisely, a recursive function or definition


is defined in terms of itself.
• Recursion is a computer algorithm that calls itself
in a steps having a termination condition.
• The successive repetitions are processed up to
the critical step where the condition is met.
• In recursive algorithms, each repetition is
processed from the last one called to the first.
• Recursion is a wonderful technique for dealing
with many problems where problems and sub-
problems have same mechanism to solve it.
Merits and Demerits of Recursion
• Recursive solutions are much easier to conceive
of and code than their iterative counterparts.
• Every problem is not solvable using this
approach
What kinds of problems are solved with
recursion?
• Generally, problems which are defined in terms
of themselves are usually good candidates for
recursive techniques.

Example
• Finding factorial of a number is an easiest
example one can think using recursion
Recursive Mathematical Model
• Since n! can be computed as: 5! = 5*4*3*2*1.
• If we have a close look at this, we notice that
5! = 5*4!. 5! = 5*4*3*2*1 = 5*4! = 5*4*3! = 5*4*3*2!
F (n) = 5! = n.F (n − 1) = n.(n − 1).F (n − 2) = n.(n − 1).(n − 2).F (n − 3)
• Now if denote F(n) = n! then it can be written as
0! = 1
F(n) = n.F(n-1) F (0) = 1

• Assume 0! = 1 i.e. F(0) = 1, and solve till


termination
F(n) = n.F(n-1) = n.(n-1).F(n-2) = n.(n-1).(n-
2).F(n-3)
...
F(n) = n.(n-1).(n-2). . . 2.1.F(0) = n.(n-1).(n-2).
. . 2.1.1
1 if n = 0
F ( n) = 
n.F (n − 1) otherwise
Solving Recurrence
• The indispensable last step when analyzing an
algorithm is often to solve a recurrence
equation.
• With little experience recurrence equation can
be solved by intelligent guesswork.
• However, there exist a powerful techniques that
can be use to solve certain classes of recurrence
almost automatically.
• This is a main topic of this lecture, techniques
solving recurrence equations of form:
– First order linear homogenous recurrences
– Second order linear homogenous recurrences
– Higher order recurrences
FIRST ORDER LINEAR HOMOGENOUS
RECURRENCE RELATIONS WITH
CONSTANT COEFFICIENTS (FOLHRRCC)
Definition and Examples of FOLHRRCC
Definition
ak = A  ak −1  k  1
where A is a real numbers and A  0

ak = 2.ak −2 No

b k = 5bk −1 YES
1
ck = k ck −1 No
2
ak = ak −1 ak −1
No
Solving First Order Recurrences
Solve the recurrence: b k = a.bk −1 if b0 = c

Solution:
bk = a.bk-1
bk = a.(a. bk-2) = a2. bk-2
bk = a2.(a. bk-3) = a3. bk-3
...
bk = ak. bk-k = ak. b0
bk = ak.c
Now the explicit formula is c.ak which is a geometric
sequence.
Hence first order recurrence is nothing but G.S.
Solving First Order Recurrences
Example
Solve the recurrence: b k = 5bk −1 if b0 = 3
Solution
bk = 5.bk-1
bk = 5.(5. bk-2) = 52. bk-2
bk = 52.(5. bk-3) = 53. bk-3
...
bk = 5k. bk-k = 5k. b0 = 5k.3
Now the solution sequence becomes
3.50, 3.51, 3.52, 3.53, 3.54, . . , 3.5k, . . .
3, 15, 75, 375, . . .geometric sequence
SECOND ORDER LINEAR HOMOGENOUS
RECURRENCE RELATIONS WITH CONSTANT
COEFFICIENTS
Definition and Examples of SOLHRRCC
Definition
ak = A  ak −1 + B  ak −2  k  2
where A and B are real numbers with B  0

ak = 3ak −1 + 2ak −2 YES

b k = bk −1 + bk −2 + bk −3 NO

1 3
c k = ck −1 − ck −2
2 7 YES
Some More Examples

dk = d 2
k −1 + d k −1  d k − 2 NO

e k = 2ek −2 YES

f k= 2 f k −1 + 1 NO

g k = g k −1 + g k -2 YES

h k = (−1)hk −1 + (k − 1)hk −2 NO
Theorem
Theorem: Let A and B are real numbers. A recurrence of the form
ak = Aa k −1 + Ba k −2
is satisfied by the sequence

1, t , t ,....t ,....t  0
2 n

where t is a non - zero real no, if and only if t satisfies the


equation : t 2 − At − B = 0
Proof: Let us suppose that the sequence

1, t , t ,..., t ,..., where, t  0


2 n

Satisfies the recurrence relation


ak = Aa k −1 + Ba k −2
Contd...
It mean each form of sequence is equal to A times the
previous form plus B times the form before it
k −1 k −2
Hence t = At
k
+ Bt
k −2
since t  0  t 0
Dividing both sides by t k −2
t − At − B = 0
2

Conversely suppose that t 2 − At − B = 0


 t k = At k −1 + Bt k − 2
2 3 n satisfies the above
Hence 1, t , t , t ..., t ... recurrence relation
Characteristic Equation
Definition: Given a second order linear homogeneous recurrence
relation with constant coefficients
ak = A  ak −1 + B  ak −2 k  2
The characteristic equation of the relation is
t 2 − At − B = 0
Example 1: Using characteristic equation, find solution to a
recurrence relation
ak = ak −1 + 2  ak −2 k  2
Find all sequences that satisfy relation and have the form
1, t , t 2 ,..., t n ,..., t  0
Solution: Above recurrence relation is satisfied by a sequence
1, t , t ,..., t ,..., t  0
2 n
Contd...

if and only if, t − t − 2 = 0


2

 (t − 2)(t + 1) = 0  t = 2,−1
Hence
0 2 3 n
2 ,2,2 ,2 ,...,2 ,... and
(− 1) , (− 1) , (− 1) , (− 1) ,...
0 1 2 3

are both particular solutions for this recurrence relation


Repeated Roots

Theorem
Let A and B be real numbers, and suppose that the
characteristic equation

t − At − B = 0
2

has a single root r, than the sequences

2 n 2 3 n
1, r , r ,..., r and 0, r ,2r ,3r ,..., nr ...
Both satisfy the recurrence relation

ak = Aa k −1 + Ba k −2
Repeated Roots
Proof
if t 2 − At − B = 0
has a single repeated root ‘r’ than
t − At − B = ( t − r )
2 2

 t 2 − At − B = t 2 − 2rt + r 2
 A = 2r and B = −r 2
We know that rn is a solution. Now we prove that S n = nr n
is also a solution, i.e.

S n satisfies the recurrence relation ak = Aa k −1 + Ba k −2


i.e., Sk = AS k −1 + BS k −2 = krk
Repeated Roots
In fact we have to prove that
A.S k −1 + B.S k −2 = k .r k
Consider t he left hand side
(
AS k −1 + BS k − 2 = A (k − 1)  r k −1
)+ B((k − 2)  r )k −2

k −1 k −2
= 2r  (k − 1)  r − r  (k − 2)  r
2

= 2(k − 1)  r − (k − 2)r
k k

= (2k − 2 − k + 2)r k

= k.r = RHS,
k
hence proved
Repeated Roots
Example 1: Single root case
Suppose sequence, b0, b1, b2,. . . satisfies recurrence relation

bk = 4bk −1 − 4bk −2 k  2
with initial condition : b 0 = 1 and b1 = 3
then find the explicit formula for b0, b1, b2, . . .

Solution: Characteristic equation t 2 − 4t + 4 = 0

(t − 2)2 = 0  t = 2, is repeated root


2n and n.2n are sequences which satisfy th e same
recurrence relation, but do not satisfy th e initial conditions
Repeated Roots
Suppose general solution : b n = C.2 n + D.n.2 n
which satisfies the original recurrence , C and D are constants
Since b0 = 1, b1 = 3
For n = 0, C + D  0  20 = 1  C = 1

For n = 1, b1 = C  21 + D 1 21
3− 2 1
 2C + 2 D = 3  2 1 + 2 D = 3  D = =
2 2
1 n n
Hence, bn = 1 2 +  n  2 = 2 1 + 
n n

2  2
 n n
= 1 + 2 is the required solution for repeated roots.
 2
Checking Explicit Formula
bn = (1 + n/2).2n
First term
b0 = (1 + 0/2).20 = 1.1 = 1
Second term
b1 = (1 + 1/2).21 = 3/2.2 = 3
Third term
b2 = (1 + 2/2).22 = 2.4 = 8
Fourth term
b3 = (1 + 3/2).23 = 5/2.8 = 20, and so on
Theorem (Linear Combination is also a Solution)
Theorem: if r0 , r1 , r2 ,... and s0 , s1 , s2 ,...
are sequences that satisfy the some second order linear
homogeneous recurrence relation with constant
coefficients, and if C and D are any numbers then the
sequence
a0 , a1 , a2 ,...defined by the formula
an = Crn + Dsn n  0
also satisfies the same recurrence relation

Proof: Since r0 , r1 , r2 ,...,and s0 , s1 , s2 ,...


Satisfy the same second order LHRRWCC
  A and B constants real no. s.t
Aak −1 + Bak − 2 = A ( C  rk −1 + D  sk −1 ) + B ( Crk − 2 + Dsk − 2 )
Theorem = A.C  rk −1 + AD  sk −1 + BCrk − 2 + BDsk − 2
= A.C  rk −1 + BCrk − 2 + AD  sk −1 + BDsk − 2
= C ( A.rk −1 + Brk − 2 ) + D( A.rk −1 + Brk − 2 )
rk = Ark −1 + Brk −2 and sk = As k −1 + Bs k −2

If an = Crn + Dsn n0

Then we have to prove that ak = Aak −1 + Bak −2

Consider R. H. S
Aak −1 + Bak − 2 = A ( C  rk −1 + D  sk −1 ) + B ( Crk − 2 + Dsk − 2 )
= C ( Ark −1 + Brk −2 ) + D( As k −1 + Bs k −2 )

= C (rk ) + D( sk ) = a k
 ak = Aa k −1 + Ba k −2
It proves that an = Crn + Dsn satisfies same recurrence
Solution as Linear Combination
t 2 − At − B = 0
Example 1: ak = ak −1 + 2  ak − 2
t2 − t − 2 = 0
Find a sequence that satisfies the recurrence relation
t 2 − At − B = 0

ak = ak −1 + 2  ak −2 k  2

And that also satisfies the initial condition


a0 = 1 and a1 = 8
Solution: The characteristics equation of the relation
ak = ak −1 + 2  ak −2 k  2 is

t 2 − t − 2 = 0  (t − 2)(t + 1) = 0
t = −1,2
Contd..
rn = 2 0 ,21 ,2 2 ,... and sn = (− 1) , (− 1) , (− 1) ,...
0 1 2

Are both sequence which satisfy above relation but neither one is having

a0 = 1 and a1 = 8
Now since an = Crn + Dsn also satisfies the same recurrence relation and

For n = 0 we get ao = Cro + Dso  1 = C + D (1)


ak = ak −1 + 2ak −
 an = 3  ( 2 )
n

For n = 1 we get a1 = Cr1 + Ds1  8 = 2C − D (2)  a0 = 3  ( 2 )


0

 an = 3  ( 2 )
n

Solving equation (1) and (2) we get, C = 3 and D = - 2  a1 = 3  ( 2 ) −


1

 an = 3  (2 ) − 2(− 1)
n n
Now an = Crn + Dsn
is the required sequence which satisfies the given conditions
General Homogenous Recurrence
Relations
(Constant Coefficients)
K order: General Homogenous Recurrence
• First order: linear combination of two cons.
terms,
• Second order: linear combination of three
consecutive terms,
• We extend technique of recurrence equation
with resolution of homogeneous linear
recurrence with constant coefficient, that is
recurrence of the form
a0 tn + a1 tn-1 +a2tn-2 …..+ak tn-k =
0 (1)
where ti are value we are looking for
• In equation (1), values of ti such that (1 < i < k)
are need to determine a sequence.
• Equation 1 typically has infinite many solutions,
because linear combination is also a solution.
K = 1: General Homogenous Recurrence
a0 tn + a1 tn-1 + …..+ak tn-k = 0
(1)
If we put k = 1 then above equation
becomes
a0 tn + a1 tn-1 = 0
tn = -(a1 / a0 )tn-1
• The resultant equation becomes a recurrence
relation which is
– first order
– linear
– homogenous
– with constant coefficients.
K = 2: General Homogenous Recurrence
a0 tn + a1 tn-1 + …..+ak tn-k = 0
(1)
If we put k = 2 then above equation
becomes
a0 tn + a1 tn-1 + a2 tn-2 = 0
tn = -(a1 / a0 )tn-1 - (a2/ a0 )tn-2 = c1tn-1 + c0
tn-2
• This time we have a recurrence relation which is
– second order
– linear
– homogenous
– with constant coefficients.
K = 3: General Homogenous Recurrence
a0 tn + a1 tn-1 + …..+ak tn-k = 0
(1)
If we put k = 3 then above equation
becomes
a0 tn + a1 tn-1 + a2 tn-2 + a3 tn-3 = 0
tn = -(a1 / a0 )tn-1 - (a2/ a0 )tn-2 - (a3/ a0 )tn-3

• This is a recurrence relation which is


– third order
– linear
– homogenous
– with constant coefficients.
• Similarly we can have fourth order and higher
order recurrence relations.
Characteristics of General Recurrence
a0 tn + a1 tn-1 + …..+ak tn-k = 0 (1)
The recurrence is:
Linear because it does not contain terms of the form tn-i
.tn-j ,t2n-i and so on
Homogeneous because the linear combination of the tn-i
equal to zero
This is Kth order because current term is linear
combination of previous k number of terms
Constant coefficients because all ai are constants
Example:
Consider Fibonacci sequence: fn = fn-1 + fn-2
This recurrence fits Eq. (1) after obvious rewriting.
fn - fn-1 - fn-2 = 0
Observation of Homogenous Recurrence

fn - fn-1 - fn-2 = 0
The Fibonacci sequence corresponds to a second
homogeneous linear recurrence relation with constant
coefficient, where
k = 2,
a0 =1,
a1 = -1
a2 = -1
Before we even start to look for solutions to Equation 1, it
would be interesting to note that any linear combination of
solutions is itself a solution.
Theorem
Statement: Prove that any linear combination of solutions of
equation given below is also a solution.
a0 tn + a1 tn-1 + …..+ak tn-k = 0
Proof: Assume that fn and gn are solutions of above
equation and hence satisfy it, i.e.
k k

a f
i =0
i n −i = 0 and  ai g n −i = 0
i =0

If we set tn = c.fn + d.gn for arbitrary constants c and d, we


have to prove that tn is also solution, i.e.,

a0tn + a1tn-1 +……+ ak tn-k = 0


Theorem

a0tn + a1tn-1 +……+ ak tn-k =


a0 (cfn + dgn) + a1(cfn-1+ dgn-1) + . . .+ak(cfn-k+dgn-k) =
c( a0fn + a1fn-1 + . . .+ akfn-k ) +d(a0gn + a1gn-1 + . . .+ akgn-k)
=
= c.0 + d.0 = 0
Hence a0tn +a1tn-1 +……+ ak tn-k = 0

Note :
It is to be noted that this rule can be generalized to linear
combinations of any number of solutions.
More Generalized Results
Statement:
If fn, gn and hn are solutions to recurrence below then their
linear combination is also a solution a0 tn + a1 tn-1
+ …..+ak tn-k = 0
Proof: As fn , gn and hn are solutions of above, hence
k k k

a f
i =0
i n −i = 0, a g
i =0
i n −i = 0, and  ai hn −i = 0
i =0

Let tn = c.fn + d.gn + e.hn for arbitrary constants c, d and e,


now we prove that tn is also solution, i.e.,

a0tn + a1tn-1 +……+ ak tn-k = 0, easy to prove


Conclusion

Why recurrence?
Type of recurrences
Techniques solving recurrences
Generalized form of recurrence
Linear combination of solutions itself solution
Reusability of models when initial conditions are
changed but pattern remains same
It empowers the recursive models to be used in more
general phenomena
Easy implementation

You might also like