Recurrences Notes
Recurrences Notes
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
t0 = j
tn = j + n
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-
2
Recall that 1/n−k = nk , and we have
rn−2 (r2 − 5r + 6) = 0
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.
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
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
(r − 1)(r − 2)3 = 0,
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
5
2 Part II
2.1 Nonhomogeneous Linear Recurrences
A nonhomoegeneous linear recurrence has the form def.
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)
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
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
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
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.
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
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
(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
11