Lecture 8

advertisement
Department of Computer Science
Logic and Discrete Structures
Institue of Business Administration
Week 8
Recurrence Relation
The specification of a sequence of values in terms of earlier values in the sequence and
base values is called a recurrence relation. A recurrence relation is also known as
recurrence equation or simply a recurrence.
Example 1: Fibonacci numbers is a sequence of numbers such that each number is the
sum of the preceding two. It can be described by the recurrence relation:
F(n) = F(n – 1) + F(n – 2), where F(1)=1 and F(2)=1.
Example 2: Execution times (also known as complexities) are often computed by setting
up then solving a unary recurrence relation, such as:
T(n) = 2T(n / 4) + 2.
First, we like to examine some basic properties of recurrences and the ways in which they
are classified. Then, we examine exact solutions to “first order” recurrences, where a
function on n is expressed in terms of the function evaluated at n – 1. We also look at
exact solutions to higher order linear recurrences with constant coefficients. Next, we
look at a variety of other types of recurrences and examine some methods for deriving
approximate solutions to some nonlinear recurrences and recurrences with non-constant
coefficients.
Recurrence relations are also commonly called difference equations because they may be
expressed in terms of the discrete difference operator A n  A n – A n – 1. They are the
discrete analog of ordinary differential equations. Techniques for solving differential
equations are relevant because similar techniques often can be used to solve analogous
recurrences. In some cases there is an explicit correspondence that allows one to derive
the solution to a recurrence from the solutions to a differential equation. We can deal with
many of these recurrence relations in a rigorous, systematic way using generating
functions, as discussed in detail in the next chapter.
Linear Homogeneous Recurrence with Constant Coefficient
A relation of the form:
a0 An + a1 An – 1 + a2 An – 2 + ….. + ai – 1 An – i + 1 + ai An – i = 0; (Equ. 1)
where ais are constants is called linear homogeneous recurrence with constant
coefficients of order i (note the difference of highest and the lowest index is the order of
the recurrence relation).
How to solve above equation? It is not hard to see that the (Equ.1) has a nontrivial
n
solution of the form An = r where r is some non-zero constant. So when we replace

A  by r in (Equ. 1) we get:
a0 r
n
+ a1 rn – 1 + a2 rn – 2 + ….. + ai – 1 rn – i + 1 + ai rn – i = 0
Week 8
Page 1
Department of Computer Science
Logic and Discrete Structures
 r
n–i
Institue of Business Administration
Week 8
(a0 ri + a1 ri – 1 + a2 ri – 2 + ….. + ai – 1 r1 + ai) = 0
since r is non-zero constant, we can divide by r
 a0 r
n–i
to get the following equation:
+ a1 ri – 1 + a2 ri – 2 + ….. + ai – 1 r1 + ai = 0
i
(Equ. 2)
(Equ. 2) which involves a polynomial in r of degree i and is called the characteristic
equation of the recurrence given by (Equ. 1). And the polynomial;
a0 r
i
+
a1 r
i – 1
+
a2 r
i – 2
+ ….. +
1
ai – 1 r
+
ai is called the characteristic
polynomial. Suppose the characteristic equation has solutions r 1, r2,…, ri. If these i
solutions are all different then the solution to the (Equ. 1) is a linear combination of each
of them. That means most general solution of (Equ. 1) is of the form:
n
An = c1 r1
+ c2 r2 n + ... + ci ri n
(Equ. 3)
There is a complication if some of the solutions are the same. We will see, very shortly,
how to overcome this complication.
Example 3:
Consider the first order recurrence, An – 2 An – 1 = 0;
= rn be a solution of this equation. Then above equation becomes;
Let An
n
n–1
r –2r
=0  r
n–1
n
( r – 2) = 0  r = 2  most general solution is An = c1*2
where c1 is an arbitrary constant and n = 0, 1, 2, 3, … As a matter of fact c1 = A0,
so An = A0*2
n
Example 4:
Consider the second order recurrence, An – 3 An – 1 + 2 An – 2
= rn be a solution of this equation. Then above equation becomes;
Let An
n
= 0;
n–1
r –3r
n–2
+2r
=0  r
n–2 2
2
( r – 3 r + 2) = 0  r – 3 r + 2 = 0
 (r – 1) (r – 2) = 0  r = 1 or r = 2  most general solution is An = c1* 1
n
n
+ c2* 2
n
or An = c1 + c2* 2 where c1 and c2 are arbitrary constants and n = 0, 1, 2, 3, …
Week 8
Page 2
Department of Computer Science
Logic and Discrete Structures
Institue of Business Administration
Week 8
Remark:- In case we are given initial values A0 and A1 we could determine c1 and c2
precisely.
Note:-If the characteristic equation is of third-order or
higher, finding the roots can be problematic. Mathematical
tables, symbolic mathematical software, or numerical rootfinding programs can sometimes be useful.
Repeated Roots
Some characteristic equations give multiple copies of the same root. Let us suppose that a
root r1 of characteristic equation is of multiplicity m, then m independent solutions of the
n
m–1 n
n
equation (Equ. 1) are given by r1 , n r1 , ... , n
r1 . And the general solution of
equation (Equ. 1) is a linear combination of these terms and of the terms contributed by
the other roots of the characteristics polynomials.
Example 5: Consider the recurrence
if n  0, 1 or 2

n
A 
n 5A
 8A
4A
otherwise
n-2
n -3
 n -1
First we write the recurrence.
An – 5A n – 1 + 8 An – 2 – 4 An – 3 = 0;
3
2
2
The characteristic polynomial of this recurrence is r – 5 r + 8 r – 4 = (r – 1) (r – 2) .
The roots are therefore r1 = 1 of multiplicity 1and r2 = 2 of multiplicity 2, and the
n
n
n
n
n
general solution is An = a 1 + b 2 + c n 2 = a + b 2 + c n 2 .
The initial conditions give
a+b
= 0
for n = 0
a+2b +2c = 1
for n = 1
a+4b +8c = 2
for n = 2
Solving these equations, we obtain a = – 2, b = 2 and c = – 0.5. Therefore
An = – 2 + 2
n+1
n–1
–n2
is the unique solution of the recurrence.
Complex Roots
Week 8
Page 3
Department of Computer Science
Logic and Discrete Structures
Institue of Business Administration
Week 8
Suppose there are complex roots of the characteristic equation. Then if
solution then
  i
must be another solution (why ?). Now
(where (, ) are the polar co-ordinates of the point
  i
  i
=
is one
 e  i
( ,  ) ). Hence the contribution to
the general solution due to this complex pair is c1  e
cos n + b sin n) where a and b are arbitrary constants.
(
i n
)
+ c2
( e-i)n =  n (a
Example 6:
Consider the second order recurrence, An + An – 2
Let An
= r n be a solution of this equation. Then above equation becomes;
n–2
n
= 0;
r +r
=0  r
r =  i r = e

or An = A0* cos (
n–2 2
2
(r + 1) = 0  r + 1 = 0

i
n
n
) + b* sin ( )
2  most general solution is A n = a* cos (
2
2
n
n
) + A1 * sin ( ) where A0 and A1 are initial values and n = 0, 1,
2
2
2, 3, … In this case it is not hard to see that
An = – A0 for n = 2, 6, 10, ….
An = – A1 for n = 3, 7, 11, ….
An =
A0 for n = 4, 8, 12, ….
An =
A1 for n = 5, 9, 13, ….
Inhomogeneous Recurrences A recurrence of the form:
a0 An + a1 An – 1 + a2 An – 2 +…+ ai – 1 An – i + 1 + ai An – i = fn;
(Equ. 4)
is called an inhomogeneous linear recurrence with constant coefficients. This is not hard
to see that the most general solution of (Equ. 4) is a combination of two parts:
1. First part is called complimentary function (or homogeneous solution) and is in
fact the general solution of the corresponding homogeneous equation (Equ. 1).
2. Second part is called particular solution and is in fact a solution of (Equ. 4) which
contains no arbitrary constants.
c
If the complimentary function is denoted by An and the particular solution is denoted
p
c
p
An , then An = An + An is the most general solution of (Equ. 4).
Week 8
Page 4
Department of Computer Science
Logic and Discrete Structures
Institue of Business Administration
Week 8
The Basic Method for Finding the Particular Solution
This is the part of the total solution which depends on the form of the RHS (right hand
side) fn, of the recurrence relation. Guess a solution of the same form but with
undetermined coefficients which have to be calculated. We find their values by inserting
the particular solution into the recurrence relation.
How to guess the form of the particular solution?
The form of the particular solution has nothing to do with the order of the recurrence
relation. It only depends on the form of the RHS (fn) and the form of the homogeneous
solution:
p
 If fn is a polynomial of degree d in n, we will guess, for An , polynomial of the same
degree, but with unknown coefficients (i.e. we will try an arbitrary polynomial of
degree d), to be determined by substituting this polynomial for A n in (Equ. 4).
However this does not work if 1 is a root of the characteristic equation. In such case
we multiply the above guess by n
m
where m is the multiplicity of the root 1.
n
 If fn = c , where c is a constant and c
n
does not appear in the complementary
p
n
function, i.e., c is not a root of the characteristic equation, we will try A n = k c ,
where k is a constant to be determined. If c is a root, of multiplicity m, of the
p
characteristic equation, we will try An = k n
m n
c .
n
n
 If fn = c (some polynomial of degree d in n) where c is a constant and c does not
p
n
appear in the complementary function, we will try An = c (an arbitrary polynomial
of degree d in n), where the arbitrary constants in the polynomial are to be determined.
p
If c is a root, of multiplicity m, of the characteristic equation, we will try A n = n
m
n
c (an arbitrary polynomial of degree d in n).
Example 7:
Consider the second order recurrence, An – 3 An – 1 + 2 An – 2
c
n
= 7 + 3 * 2n;
p
n
p
From Example 4, An = c1 + c2* 2 , so we try An = A n + B n 2 . As An is a
solution of the recurrence, we must have
n
(A n + B n 2 ) – 3(A (n –1) + B (n –1) 2
Week 8
n–1
) + 2(A (n –2) + B (n–2) 2
n–2
n
)=7+3*2 ;
Page 5
Department of Computer Science
Logic and Discrete Structures
 –A + B 2
n–1
=7+3*2
n
Institue of Business Administration
Week 8
c
p
 A = –7 & B = 6  An = An + An = c1 + c2* 2
n
–7
n
+ 6 n 2 is the most general solution.
Example 8:
Consider the second order recurrence, An – 2 An – 1
c
n
p
= 2 * n 2, A2 = 0;
2
p
Here An = B * 2 , so we try An = C n + D n + E. As An is a solution of the
recurrence, we must have
2
2
2
C n + D n + E – 2 (C (n – 1) + D (n – 1) + E) = 2 * n ;
2
2
 – C n + (4 C – D) n –2 C + 2D – E = 2 * n  C = – 2, D = – 8, E = – 12,  An =
c
p
n
2
An + An = B * 2 –2 n – 8n – 12 is the most general solution. Now A2 = 4 B – 8 –
n
2
16 – 12 = 0  B = 9. Hence An = 9 * 2 –2 n – 8n – 12 is the particular solution.
Remark
Systems like Mathematica and Maple have packages for solving recurrences of above
forms and many other types.
Assignment
1- Solve the recurrence given in Example 1.
2- Solve the recurrence An – 7 An–1 + 15 An–2 – 9 An–3 = 4 + 3 * 4 n – 3;
subject to Ai = i for i = 0, 1, 2.
3- Consider the third order recurrence,
An – 6 An–1 + 11 An–2 – 6 An–3 = 0;




Are there initial conditions for which the solution is An = 3n ?
Are there initial conditions for which the solution is An = 2n ?
Are there initial conditions for which the solution is An = 3n – 2n ?
Are there initial conditions for which the solution is bounded? If so,
find these initial conditions. Do you have exactly one such set, or
there are infinitely many such sets?
Recall that a bounded solution means that An remains finite even if n
goes to infinity.
Week 8
Page 6
Department of Computer Science
Logic and Discrete Structures
Institue of Business Administration
Week 8
n
n
4- Solve the recurrence An = – An–3 + 2 + (–1) + 1
subject to An = 0
for n > 2;
for n = 0, 1, 2.
5- Solve the recurrence An+3 – 3 An+1 – 2 An = 4n + 6(–1)n + 18 * 2 n;
subject to An = (–1)n for n = 0, 1, 2.
6- Solve the following inhomogeneous fourth order recurrence:
n
An+3 + 3An+1 – 4An–1 = 10 + (18+20n)(–1) for n > 0;
and
An = n
for n = 0, 1, 2 and 3.
Some Nonlinear and Nonconstant Coefficients Recurrences
In case of nonconstant recurrences one typically uses the
techniques of generating functions or of approximations
methods. But in few cases some higher-order problems can be
solved with summation factors. For example, the recurrence
–
An = nAn – 1 + n(n 1) An – 2 for n > 1 with A0 = 1 and A1 = 1.
Can be solved by simply dividing both sides by n!, leaving the Fibonacci recurrence in
An / n!, which shows that An = n! F(n).
For some nonlinear equations the change of variables
technique might be a useful one in the sense that the
resulting recurrence may turned out to be a liner one. As
an example consider the nonlinear second-order recurrence:
(1/2)
An = (An-1 An-2)
for n > 1 with A0 = 1 & A1 = 2.
If we take the logarithm of both sides of this equation and make the change of variables
Bn = lg An, then we find that Bn satisfies:
Bn = (Bn-1 + Bn-2) / 2 for n > 1 with B0 = 0 & B1 = 1.
Which is linear recurrence with constant coefficients.
Non-constant Coefficient (Summing Factors)
If the coefficients are not constants, then more advanced
techniques
are
needed.
Summing
factor
is
one
such
technique.
This
technique
is
the
analogue
of
the
integrating factor technique for solving differential
equations. The technique is applicable to any linear,
Week 8
Page 7
Department of Computer Science
Logic and Discrete Structures
Institue of Business Administration
Week 8
first-order recurrence relation (however it is mostly used
by recurrences having non-constant coefficient). As an
example, consider the recurrence:
The two functions BN and CN can be almost any functions of N. The way we remove the
BN so that it becomes a simple recurrence relation is to make a substitution of variables:
A0=X0
With this substitution, the recurrence relation becomes:
Now you see the "almost" mentioned above. if any of the B N is zero, the solution cannot
be found. We can find the solution by performing a sequence of substitutions:
XN = XN – 1 +
CN
B1 B2 B3 ...BN
C N 1
CN
+
B1 B2 B3 ...BN 1
B1 B2 B3 ...BN
C N 1
C N 2
CN
XN = XN – 3 +
+
+
B1 B2 B3 ...BN 2 B1 B2 B3 ...BN 1
B1 B2 B3 ...BN
XN = XN – 2 +
XN = ….
When we take this sequence all the way back to the initial condition, the solution is:
If we undo the substitution of variables, the solution is
Assignment:Solve the following recurrences:
1- An = (n+2)An–1 + 2 for n > 0 with A0 = 1.
2- An= nAn–1 + n + 2 for n > 0 with A0 = 2.
Week 8
Page 8
Download