0% found this document useful (0 votes)
93 views11 pages

Recurrences Notes

1. The document discusses recurrence relations, which are equations that define a term (tn) in terms of previous terms. It provides definitions and examples of homogeneous linear recurrence relations with constant coefficients. 2. It demonstrates solving a sample recurrence relation (tn - 5tn-1 + 6tn-2 = 0) by deriving its characteristic polynomial and finding the roots, which provide the solutions to the recurrence relation. 3. The general solution to a homogeneous linear recurrence is a linear combination of terms raised to the powers of the characteristic polynomial's roots, with coefficients determined by initial conditions.

Uploaded by

Vasikaran K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views11 pages

Recurrences Notes

1. The document discusses recurrence relations, which are equations that define a term (tn) in terms of previous terms. It provides definitions and examples of homogeneous linear recurrence relations with constant coefficients. 2. It demonstrates solving a sample recurrence relation (tn - 5tn-1 + 6tn-2 = 0) by deriving its characteristic polynomial and finding the roots, which provide the solutions to the recurrence relation. 3. The general solution to a homogeneous linear recurrence is a linear combination of terms raised to the powers of the characteristic polynomial's roots, with coefficients determined by initial conditions.

Uploaded by

Vasikaran K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Recurrence Relations

September 16, 2011

Adapted from appendix B of Foundations of Algorithms by Neapolitan and


Naimipour.

1 Part I
1.1 Definitions and the Characteristic Function
A recurrence relation is a relation in which tn is defined in terms of a smaller def.
value of n. A recurrence does not define a unique function, but a recurrence
together with some initial conditions does define a unique function. The initial
conditions gives the values of ti for some set of i’s starting with i = 0. def.
A solution to a recurrence relation for a given set of initial conditions is an def.
explicit function that defines tn without using any ti in the definition of tn .
For example , the relation ex.

tn = tn−1 + 1

is a recurrence relation and if the initial condition is

t0 = j

for any value j, then the solution to tn = tn−1 + 1 is

tn = j + n

A homogeneous linear recurrence equation with constant coeffi-


cients is an equation of the form def.

a0 tn + a1 tn−1 + ... + ak tn−k = 0

Let’s go through that step by step.


• It’s linear because every term tk appears in the first power and term n def.
depends on a sequence of n − k terms for an integer k.
• Its homogeneous because it equals 0. def.
• and it has constant coefficients.

1
For example , let’s solve the recurrence relation ex.
tn − 5tn−1 + 6tn−2 = 0 (1)
First off, note that its a homogeneous linear recurrence relation with constant
coefficients.
Linear systems theory leads us to set
tn = rn
For some non-zero value of r. We don’t know what r is, but we are going to
require that the above equality holds. It remains to be proven that such an r
exists. It also remains to be proven that replacing the nth term of t with the
nth power of r results in the same solution to the recurrence relation. There
are two ways to argue that replacing tn with rn gives a correct solution to the
recurrence relation. First, we don’t have to know beforehand that tn = rn
is going to work. After we find the roots of the characteristic function, we
can verify that the substitution worked by testing the solution on some values.
Second, we can prove that this substitution will work in general for any linear
constant-coefficient homogeneous recurrence relation. That deeper answer is
beyond the scope of the class but if you are interested, we recommend the text
by Luenberger.1
Moving on, if we replace tn with rn in Equation 1 then we get the charac-
teristic function for the recurrence relation def.
rn − 5rn−1 + 6rn−2 = 0 (2)
We can now see that setting tn = rn is a solution to Equation 1 if r is a root
of Equation 2.
Why is that? Since we have
tn − 5tn−1 + 6tn−2 = rn − 5rn−1 + 6rn−2 = 0
the roots of the polynomial in r are the values of r in which the polynomial
equals zero. At those values of r, the values of the functions of both r and tn
work out to be zero–as required by the recurrence relation.
So what are the roots of
rn − 5rn−1 + 6rn−2 = 0? (3)
First, multiply the left side through by rn−2 /rn−2 to get
 n
rn−1 rn−2

r
rn−2 − 5 + 6 =0
rn−2 rn−2 rn−2
simplify the fractions in one step:
 
1 1 1
rn−2 − 5 + 6 =0
r−2 r−1 1
1 David G. Luenberger, Introduction to Dynamic Systems: Theory, Models, and Applica-

tions, 1979, John Wiley and Sons.

2
Recall that 1/n−k = nk , and we have

rn−2 (r2 − 5r + 6) = 0

Then we can factor the polynomial into

rn−2 (r − 2)(r − 3) = 0

We assumed that r is non-zero, so we can divide by the first factor rn−2 , which
leaves
(r − 2)(r − 3) = 0
Thus, the characteristic function (also: polynomial) remains on the left-hand
side. Its roots are 2 and 3.
Now we go back and check that the roots are solutions to the recurrence
relation. So we let
tn = 3n or tn = 2n .
In this example , we let tn = 3n and show that ex.

3n − 5(3n−1 ) + 6(3n−2 ) = 0.

To do this, we first recall that


1 n−1
3n−2 = 3−1 3n−1 = 3
3
so that we can get
3n − 5(3n−1 ) + 2(3n−1 ) = 0
which is
3n − 3(3n−1 ) = 0
and note again that
1 n
3n−1 = 3−1 3n = 3
3
which leaves us with
3n − 3n = 0.
We have just verified that tn = 3n is a solution for Equation 1. Note that we
have not shown for which initial values 3n is a solution, but we have shown that
it is a solution. The second homework problem is to show that tn = 2n is a
solution as well. And the third homework problem is to show that any linear
combination of 2n and 3n is a solution.

3
1.2 Finishing Linear Homogeneous Recurrences
First off, we need to wrap up solving linear homogeneous recurrences using the
characteristic function. The final piece we need is a method for determining
which values of c1 and c2 give solutions to a recurrence relation for a given set
of initial values. The equation

tn = c1 3n + c2 2n

is called the general solution to the recurrence. We want the solution for a def.
given set of initial values. To do this, we simply plug in values of the initial
conditions and solve for the c’s. We can do this because we end up with n
functions of n variables.
Returning to the example from the previous section, if we set ex.

t0 = 0 and t1 = 1

then we can determine c1 and c2 by solving the system of equations

t0 = c1 30 + c2 20 = 0

and
t1 = c1 31 + c2 21 = 1
If you remember your linear algebra, then you will quickly see that the solution
is c1 = 1 and c2 = −1. If you don’t then here’s a quick review (or tutorial). The
basic idea is to pick a variable ci , multiply one equation by a constant and add
the equations together to eliminate ci . You pick the constant carefully (basically
you pick −aj /ai where aj is the coefficient on ci in the other equation and ai is
the coefficient of ci ) so that the sum involving that term works out to 0.
Like so... Multiply the top equation by -3

c1 30 + c2 20 = 0
c1 31 + c2 21 = 1

to get
−3c1 + −3c2 = 0
3c1 + 2c2 = 1
then add the equations and

−3c1 + −3c2 = 0
3c1 + 2c2 = 1
−c2 = 1

so c2 = −1. Repeat the process, re-starting with the original system of equations
to eliminate c2 (hint: multiply the top equation by -2) and you find that c1 = 1.
In the end, the solution is

tn = 1(3n ) − 1(2n ) = 3n − 2n

4
if t0 = 0 and t1 = 1 .
One last point. If we factor the characteristic function and find that one of
the (r − i) terms is duplicated j times, then i is a root of multiplicity j. For def.
example , if we get the characteristic equation down to ex.

(r − 1)(r − 2)3 = 0

then the characteristic equation has 2 as a root of multiplicity 3.


If a characteristic function has a root r of multiplicity j, then the following
terms
tn = rn , tn = nrn , tn = n2 rn and tn = nj−1 rn (4)
must appear in the general solution (...multiplied by different constants in the
sum of terms). This keeps each of the terms linearly independent, thus forming
an appropriate basis for all solutions. For our example of

(r − 1)(r − 2)3 = 0,

The general solution is

tn = c1 · 1n + c2 · 2n + c3 · n2n + c4 · n2 2n

1.3 Homework
1. Which of the following are homogeneous linear recurrences with constant
coefficients?
6tn + 1tn−1 + 4tn−2 = 0
43tn + 5tn/2 + tn/4 = 0
tn + 8tn + 4tn−2 = 5
8tn tn−2 + 51tn−1 + tn−2 = 0

2. Verify that tn = 2n is a solution to Equation 1 (from the example on


page 2). Note that we verified that tn = 3n is a solution to Equation 1
earlier in this section.

3. Verify that c1 3n + c2 2n is a solution for Equation 1 (also from the example


on page 2) for any constants c1 and c2 . The equation c1 3n + c2 2n is called
the general solution to a recurrence relation.
4. Solve tn = 4tn−1 − 3tn−2 for n > 1 with t0 = 0 and t1 = 1 using the
characteristic function. (Hint: you have to convert it to a homogenous
recurrence first. This is not hard.)

5
2 Part II
2.1 Nonhomogeneous Linear Recurrences
A nonhomoegeneous linear recurrence has the form def.

a0 tn + a1 tn−1 + ... + ak tn−k = f (n)

where f (n) 6= 0. There is no known general solution technique for nonhomoge-


neous linear recurrences. So we will solve recurrences of the form

a0 tn + a1 tn−1 + ... + ak tn−k = bn p(n) (5)

where p(n) is a polynomial in n. The right-hand side is known as a geometric


forcing function; ”geometric” refers to the growth in the exponential term, def.
and ”forcing function” refers to the fact that the function provides the input to
the system.
First, we will do an example using the brute force approach with p(n) = 1. ex.
Solve the recurrence
tn − 3tn−1 = 4n
What we want are two versions of the recurrence that are equal to 4n−1 . Then
we can subtract them and get a homogeneous recurrence. To get the first one,
replace n with n − 1.
tn−1 − 3tn−2 = 4n−1 .
We can do that because the recurrence also defines tn−1 and tn−2 and so forth
all the way down to tn−k+1 . To get the second one, divide the recurrence by 4.
tn 3tn−1
− = 4n−1
4 4
Both of these recurrences have the same solution as the original recurrence. We
subtract them to eliminate the 4n−1 term and get
tn 7tn−1
− + 3tn−2 = 0
4 4
which is a linear homogeneous recurrence that we already know how to solve.
In general, we have the following theorem which is a convenient shortcut
to the brute force approach above: A nonhomogeneous linear recurrence of the
form
a0 tn + a1 tn−1 + ... + ak tn−k = bn p(n)
can be transformed into a recurrence of the form

(a0 rk + a1 rk−1 + ... + ak )(r − b)d+1 = 0 (6)

in which d is the order of the polynomial p(n). (And the order of a polynomial
is the largest exponent in the polynomial). The proof of this fact would follow
the reasoning we used to homogenize the recurrence in the last example. We

6
will omit the proof though. Note that the solution in Equation 6 has a root of
multiplicity d + 1.
For example , consider the following recurrence: ex.

tn − 3tn−1 = 4n (2n + 1)

First, we reduce it to a homogeneous recurrence using Equation 6. To do that,


we need to find k, d, b and the ai ’s. k is 1 because tn−1 is the last term in the
recurrence relation. d is 1 because the order of (2n − 1) is 1. b is 4 and a0 = 1
with ak = a1 = −3. So we have the homogenous recurrence

(1r1 − 3)(r − 4)1+1 = 0 (7)

which we know how to solve. The roots of Equation 7 are 3 and 4 and the root
4 has multiplicity 2. So the general solution is

tn = c1 3n + c2 4n + c3 n4n

which has three unknowns so we will need three initial values to get values for
the three unknowns.
If we are given less than three initial values (which we could be because the
original recurrence only needs one initial value), then we can get more initial
values by computing them. For example , if we are given the initial value ex.

t0 = 0

then we can compue t1 as

t1 − 3t0 = 41 (2(1) + 1) is t1 − 3(0) = 41 (2(1) + 1)

and t1 = 12.

2.2 Homework
1. Solve tn = 3tn−1 − 2tn−2 + n2 for n > 1 with t0 = 0 and t1 = 1 using the
characteristic function. (Hint: Cast the recurrence relation into the form
of equation 6 and solve it using the shortcut method.)

7
3 Part III
3.1 Change of variables (Domain Transformation)
Many of the recurrences that describe Divide and Conquer algorithms are not
of the form that we can directly solve using the techniques we have studied thus
far. These recurrences usually have the form:
tn = l · tn÷b + g(n)
Where l and b are integers and g(n) ∈ Θ(nk ). The practice of writing the n as a
subscript gets awkward at this point. It will now be useful to write recurrences
using this equivalent notation:
t(n) = l · t(n ÷ b) + g(n)
For example, the recurrence describing the complexity of merge sort (assuming
n is a power of 2) is given as
1
t(n) = 2 · t( · n) + n
2
The t( 21 · n) term causes the recurrence to not fit our general solution. Recall
that t(n) means the same thing as tn . To solve this type of recurrence, we are
going to use a change of variables. We demonstrate this through an example def.
. Consider the recurrence ex.

n
T (n) = T( ) + 1 for n > 1, and n a power of 2
2
T (1) = 1
To change the variables to a form we can solve, first, we replace n with 2k
(which we can do because we assumed that n was a power of 2). Second, we
solve for k so that
n = 2k , which means k = lg n
k
Now substitute 2 into the expression for n
2k
T (2k ) = T( )+1
2
= T (2k−1 ) + 1
If we now set tk = T (2k ) we obtain the recurrence
tk = tk−1 + 1
so that the k element of the recurrence is the value of the recurrence for 2k (which
we can do because we assumed n was always a power of 2). This recurrence in
a form that we can solve because it is a nonhomoegeneous linear recurrence.
1 · tk − 1 · tk−1 = 1k · k 0

8
Using the general formula with b = 1 and d = 1 we get
t k = c1 + c2 k
We know need to undo our change of variables to arrive back at our original
recurrence. This is a two step process:
1. Substitute T (2k ) for tk in our general solution to the recurrence:
T (2k ) = c1 + c2 k

2. Substitute n for 2k and lg n for k in the equation from step 1:


T (n) = c1 + c2 lg n

This is the general solution to our original recurrence before the change of
variables. From this point, we proceed as normal using the initial conditions to
find values for c1 and c2 . For this recurrence, the initial condition is T (1) = 1.
We need to determine a second initial condition using the first:
T (2) = T (1) + 1
= 2
The 2 equations for the systems are:
2 = c1 + c2 lg 2
1 = c1 + c2 lg 1

c1 = 1
c2 = 1
The final solution is given as:
T (n) = 1 + lg n
Example: solving the recurrence describing merge sort: ex.
1
t(n) = 2 · t( · n) + n with n > 0 and n power of two
2
t(1) = 1
t(2) = 3
1. Change of variables: n = 2k
2k
T (2k ) = 2T ( ) + 2k
2
tk = 2tk−1 + 2k
tk − 2tk−1 = 2k k 0

9
2. Solve as an nonhomogeneous recurrence with b = 2 and k = 0:
(r − 2)(r − 2) = 0
(r − 2)2 = 0

tk = c1 2k + c2 k2k

3. Change variables back to n by substituting T (2k ) for tk ; and then substi-


tuting n for 2k and lg n for k:
T (2k ) = c1 2k + c2 k2k
T (n) = c1 n + c2 n lg n

4. Use initial conditions to find value for c1 and c2 :


1 = c1 (1) + c2 (lg 1)
3 = c1 (2) + c2 (2 lg 2)

c1 = 1
1
c2 =
2
The final solution is given as:
n
T (n) = n + lg n
2
From this, we can see that T (n) ∈ Θ(n lg n), which thankfully, is the result
we expected.

3.2 Homework
Solve the following recurrences using the above methods:
1. T (n) = 2T ( n3 ) + log3 n for n > 1, n a power of 3, and T (1) = 0
2. T (n) = 10T ( n5 ) + n2 for n > 1, n a power of 5, and T (1) = 0
3. nT (n) = (n − 1)T (n − 1) + 3 for n > 1 and T (1) = 1
Do not spend more than 2 hours working on this.

4 Summary
At this point we have three main “recipes” for solving recurrences. And to be
honest, we really only know how to solve linear homogeneous recurrences with
constant coefficients. The other two kinds of recurrences we solve by translating
them into the kind we know how to solve.
To solve a linear homogeneous recurrence with constant coefficients, do the
following:

10
1. Write down the characteristic function. This is done by setting tn = rn .
2. Solve for the roots of the characteristic function, which is a polynomial.
Idealy, this is done by factoring the characteristic function and writing
down the roots. In the worst case, you’ll have to use the quadratic equa-
tion.

3. Write down the general solution. This is a function of the form

tn = c1 4n + c2 2n

where the constants may be different. Also, add extra terms for roots of
multiplicity n using Equation 4 (on page 5).
4. Use the initial conditions to find the specific solution for that set of initial
conditions by solving for the constants in the general solution. You may
have fewer initial conditions than constants in the general solution. In this
case, you’ll have to pump the recurrence relation with the initial conditions
to get some values.
To solve a linear nonhomogeneous recurrence with constant coefficients of
the form
a0 tn + a1 tn−1 + ... + ak tn−k = bn p(n)
replace it with a characteristic function of the form

(a0 rk + a1 rk−1 + ... + ak )(r − b)d+1 = 0

in which d is the order of the polynomial p(n). (And the order of a polynomial
is the largest exponent in the polynomial). This characteristic function can then
be solved using the steps to solve a linear homogeneous recurrence.
To solve a recurrence of the form

t(n) = l · t(n ÷ b) + g(n)

(where l and b are integers and g(n) ∈ Θ(nk )), perform a change of variables by
1. Replace n with bk (we have to assume that n is a power of b).
2. Replace bk with tk

3. Solve as a nonhomogeneous recurrence.


4. In the resulting general solution, change the variables back by replacing
tk with T (bk ). Then replace bk with n and k with logb n.
5. This gives a new general solution (with the right variables). Use the
initial values to solve for the constants in the general solution to obtain
the solution.

11

You might also like