Substitution Method in Recurrence Relations
Substitution Method in Recurrence Relations
1 Substitution Method
Consider a computational problem P and an algorithm that solves P . Let T (n) be the worst-
case time complexity of the algorithm with n being the input size. Let us discuss a few examples
to appreciate how this method works. For searching and sorting, T (n) denotes the number of
comparisons incurred by an algorithm on an input size n.
T (n) = 1 + T (n − 1) = 1 + · · · + 1 + T (1),
T (n) = T (k) + 1 + · · · + 1.
1
T (n) = Θ(log2 (n)).
Similar to binary search, the ternary search compares x with A[n/3] and A[2n/3], and the
problem size reduces to n/3 for the next iteration. Therefore, the recurrence relation is
n
T (n) = T + 2,
3
and T (2) = 2. Note that there are two comparisons done at each iteration, and due to which
the additive factor 2 appears in T (n).
n n n
T (n) = T +2 ⇒ T =T +2
3 3 9
n
⇒ T (n) = T k + 2 + 2 + · · · + 2 (2 appears k times)
3
When n = 3 ,k
T (n) = Θ(n2 )
2
1.2.1 Merge Sort
Approach: Divide the array into two equal sub-arrays and sort each sub-array recursively. Do
the sub-division operation recursively till the array size becomes one. Trivially, the problem size
one is sorted and when the recursion bottoms out, two sub-problems of size one are combined to
get a sorting sequence of size two, further, two sub problems of size two (each one is sorted) are
combined to get a sorting sequence of size four, and so on. We shall see the detailed description
of merge sort when we discuss the divide and conquer paradigm. To combine two sorted arrays
of size n2 each, we need 2 + 2 − 1 = n − 1 comparisons in the worst case. The recurrence for the
merge sort is,
" #
n n n
T (n) = 2T + (n − 1) = 2 2T 2 + − 1 + (n − 1)
2 2 2
n
⇒ 2k T + (n − 2k ) + (n − 2k−1 ) + · · · + (n − 1).
2k
When n = 2k ,
T (n) = 2k T (1) + n + · · · + n − 2k−1 + · · · + 20 .
Note that
2k − 1
2k−1 + · · · + 20 = = 2k − 1 = n − 1.
2−1
Also, T (1) = 0 as there is no comparison required if n = 1. Therefore,
3
1.3 Finding Maximum
To find the maximum in an array of n elements, we first assume the first element is the maximum
and start comparing this local maximum with the rest of the elements linearly. Update the local
maximum, if required. The base case: T (2) = 1 or T (1) = 0.
Let T (n) denote the worst-case number of comparisons to find the maximum, then
T (n) = T (n − 1) + 1
⇒ T (2m ) = 2 × T (2m/2 ) + 1
⇒ T (2m ) = 2 × T (2m/2 ) + 1
Let us introduce another change by letting S(m) = T (2m ).
⇒ S(m) = 2 × S(m/2) + 1
⇒ S(m) = 2 × 2 × S(m/4) + 1 + 1
⇒ S(m) = 22 × S(m/22 ) + 2 + 1
By substituting further,
Since T (n) denotes the number of comparisons, it has to be an integer always. Therefore,
√
T (2) = 2 × T ( 2) + 1 ≈ 3.
⇒ S(m) = 3 + 2k − 1 = m + 2.
We now have S(m) = T (2m ) = m + 2. Thus,
Therefore,
T (n) = Θ(log n).
√
Problem 2: T (n) = 2T ( n) + n, T (1) = 1
Let n = 2m .
⇒ T (2m ) = 2 × T (2m/2 ) + 2m
4
Let S(m) = T (2m ).
⇒ S(m) = 2 × S(m/2) + 2m
⇒ S(m) = 2 × 2 × S(m/4) + 2m/2 + 2m
To simplify, assume m = 2k .
Hence,
S(m) = O(m2m ), T (2m ) = O(m2m ), T (n) = O(n log n).
Is it true that T (n) = Ω(n log n)? Answer: [Link]: From the first term of the above
Θ(2m ) = Θ(n).
√
Problem 3: T (n) = 2T ( n) + log n, T (1) = 1
Let n = 2m .
⇒ T (2m ) = 2T (2m/2 ) + log(2m )
⇒ T (2m ) = 2T (2m/2 ) + m
Let S(m) = T (2m ).
⇒ S(m) = 2S(m/2) + m
⇒ S(m) = 2 2S(m/4) + m/2 + m
⇒ S(m) = 22 S(m/22 ) + m + m
By substituting further,
⇒ S(m) = 2k S(m/2k ) + m + m + · · · + m
⇒ S(m) = 2 + m(k − 1) + m = 2 + mk
⇒ S(m) = 2 + m log m
⇒ S(m) = O(m log m)
⇒ S(m) = T (2m ) = T (n) = O(log n · log log n).
5
3 Recursion Tree Method
While substitution method works well for many recurrence relations, it is not a suitable tech-
nique for recurrence relations that model divide and conquer paradigm based algorithms. The
Recursion Tree Method is a popular technique for solving such recurrence relations, in particular
for solving unbalanced recurrence relations.
For example, in case of modified merge sort, to solve a problem of size n (to sort an array of
size n), the problem is divided into two problems of size n3 and 2n
3 each. This is done recursively
until the problem size becomes 1.
Consider the following recurrence relation:
1. T (n) = 2T n2 + 1
Here, the number of leaves = 2log n = n and the sum of effort in each level except leaves
is:
log2 (n)−1
X
2i = 2log2 (n) − 1 = n − 1
i=0
h i
= 22 2T 2n3 + 1 + 2 + 1 = 23 T 2n3 + 22 + 2 + 1
6
3. T (n) = 3T n4 + cn2
3 2 3 log4 (n)−1
T (n) = cn2 + 3
cn2 + cn2 cn2 + (number of leaves) × T (1).
16 16 + ··· + 16
log4 (n)−1
3 i
X
T (n) = cn2 + nlog4 (3) × T (1).
16
i=0
3 log4 (n)
2 1−
= cn · 16
3 + nlog4 (3) × T (1).
1 − 16
1
= d · cn2 1 − nlog4 (3)−2 + nlog4 (3) × T (1), where d = 3 .
1 − 16
≤ dcn2 .
Therefore,
T (n) = O(n2 ).
T (n) = Ω(n2 ).
Therefore,
T (n) = Θ(n2 ).
7
4. T (n) = T n3 + T 2n
3 + O(n)
Solution: Note that the leaves are between the levels log3 n and log3/2 n.
From the computation tree, it is clear that the maximum height is log3/2 n. Therefore, the
cost is at most
log3/2 n · cn = O(n log n).
Similarly, the minimum height is log3 n. Therefore, the cost is at least
Thus,
T (n) = Θ(n log n).
Aliter:
2n
+ O(n) and T (n) ≥ 2T n
T (n) ≤ 2T 3 3 + O(n).
5. T (n) = T n 9n
10 +T 10 +n
Solution: Note that the leaves of the computation tree are found between levels log10 n
and log10/9 n.
Assume all the leaves are at level log10 n. Then
Therefore, we conclude
T (n) = Θ(n log n).
8
4 Master Theorem
We shall now look at a method called the master theorem which is a “cook book” for many
well-known recurrence relations. It presents a framework and formulae using which solutions to
many recurrence relations can be obtained very easily. Almost all recurrences of type
T (n) = aT nb + f (n)
can be solved easily by doing a simple check and identifying one of the three cases mentioned in
the following theorem. By comparing nlogb a (the number of leaves) with f (n), one can decide
upon the time complexity of the algorithm.
Master Theorem: Let a ≥ 1 and b > 1 be constants, let f (n) be a non-negative function,
and let T (n) be defined on the non-negative integers by the recurrence
T (n) = aT nb + f (n),
where we interpret n/b to be either ⌊n/b⌋ or ⌈n/b⌉. Then T (n) has the following asymptotic
bounds:
• Case 3: If f (n) = Ω(nlogb a+ϵ ) for some constant ϵ > 0, and if af (n/b) ≤ cf (n) for some
constant c < 1 and all sufficiently large n, then
In the next section, we shall solve recurrence relations by applying the Master Theorem.
Later, we discuss a proof of the theorem and some technicalities to be understood before apply-
ing it.
Examples:
1. T (n) = 9T (n/3) + n
nlogb a = nlog3 9 = n2 , f (n) = n.
Since n = O(n2 ), Case 1 applies:
2. T (n) = T (2n/3) + 1
nlogb a = nlog3/2 1 = n0 = 1 = f (n).
Case 2 applies:
T (n) = Θ(nlogb a log n) = Θ(log n).
3. T (n) = 2T (n/2) + n
nlogb a = nlog2 2 = n, f (n) = n.
Case 2 applies:
T (n) = Θ(nlogb a log n) = Θ(n log n).
9
4. T (n) = 3T (n/4) + n log n
nlogb a = nlog4 3 , f (n) = n log n.
Since f (n) = Ω(nlogb a+ϵ ), Case 3 applies.
Regularity check:
n
af (n/b) = 3 · 4 log n4 ≤ cn log n (c = 3/4).
Hence,
T (n) = Θ(f (n)) = Θ(n log n).
5. T (n) = 4T (n/2) + n
nlogb a = nlog2 4 = n2 , f (n) = n.
Since n = O(n2 ), Case 1 applies:
6. T (n) = 4T (n/2) + n2
nlogb a = nlog2 4 = n2 = f (n).
Case 2 applies:
T (n) = Θ(nlogb a log n) = Θ(n2 log n).
7. T (n) = 2T (n/2) + 2n
nlogb a = nlog2 2 = n, f (n) = 2n.
Clearly f (n) = Ω(nlog2 2+ϵ ). Case 3 applies.
Regularity check:
af (n/b) = 2 · (n/2) = n ≤ c · 2n (c = 1/2).
Hence,
T (n) = Θ(f (n)) = Θ(2n).
Hence,
T (n) = Θ(f (n)) = Θ(n3n ).
Technicalities:
• From the above examples, it is clear that in each of the three cases, we compare the function
f (n) with the function nlogb a . Intuitively, the larger of the two functions determines the
solution to the recurrence.
– If, as in Case 1, the function nlogb a is the larger, then the solution is T (n) = Θ(nlogb a ).
– If, as in Case 3, the function f (n) is the larger, then the solution is T (n) = Θ(f (n)).
– If, as in Case 2, the two functions are the same size, we multiply by a logarithmic factor
which comes from the height of the tree, and the solution is T (n) = Θ(nlogb a log n).
10
• Also, in the first case, not only must f (n) be smaller than nlogb a , it must be polynomially
smaller. That is, f (n) must be asymptotically smaller than nlogb a by a factor of nϵ for
some constant ϵ > 0.
• In the third case, not only must f (n) be larger than nlogb a , it also must be polynomially
larger and in addition, satisfy the regularity condition that af (n/b) ≤ cf (n) for some
c < 1.
• Note that the three cases do not cover all the possibilities for f (n). There is a gap between
Case 1 and Case 2 when f (n) is smaller than nlogb a but not polynomially smaller.
• Similarly, there is a gap between Case 2 and Case 3 when f (n) is larger than nlogb a but not
polynomially larger. If the function f (n) falls into one of these gaps, or if the regularity
condition in Case 3 fails to hold, we cannot use the Master Theorem to solve the recurrence.
• We shall next discuss recurrence relations that fall into the gaps between Case 1 and 2,
and Case 2 and 3. We also look at a recurrence relation that satisfies Case 3 of the Master
Theorem but fails to satisfy the regularity condition.
Examples:
T (n) = Θ(n).
3. T (n) = 2T (n/2) + 2
n
Here, nlogb a = = n. Comparing n and f (n) = n2 , we see that n is asymptotically
nlog2 2
and polynomially larger. Therefore, Case 1 of Master Theorem applies:
T (n) = Θ(n).
4. T (n) = 2T (n/2) + n log n Here, nlogb a = nlog2 2 = n. Comparing n and f (n) = n log n, we
find:
• Case 1 does not apply since f (n) is not polynomially smaller.
• Case 2 does not apply since f (n) ̸= Θ(n).
• Case 3 does not apply since f (n) is larger than n, but only by a log n factor, not
polynomially larger.
Therefore, the Master Theorem cannot be applied here.
5. T (n) = 4T (n/2) + n2 log n
Here, nlogb a = nlog2 4 = n2 , while f (n) = n2 log n. Again, f (n) is asymptotically larger
than n2 but not polynomially larger. Hence, the Master Theorem cannot be applied.
11
6. T (n) = 2T (n/2) + n2 n1+sin(n)
Since sin(n) ∈ [−1, 1], we have f (n) ∈ [n2 , n4 ]. Since f (n) is polynomially larger than
nlog2 2 = n, this recurrence seems to satisfy Case 3.
However, it fails
√
the regularity condition. For example, at n = 270, sin(270◦ ) = −1 and
sin(135◦ ) = 22 , the inequality
af (n/b) ≤ cf (n)
fails for any c < 1. Therefore, Master Theorem cannot be applied.
Special Solutions via Recursion Tree:
1. T (n) = 2T (n/2) + log n
Contribution per level: log n, log(n − 1), log(n − 2), . . . (for log n levels).
Lower bound: T (n) ≥ log n + · · · + log n = Ω(n).
Upper bound: T (n) ≤ log(n − h) + · · · + log(n − h), with h = log n.
Hence,
T (n) = Θ(n).
2+sin(n)
2. T (n) = 2T (n/2) + n
Since 2 + sin(n) ∈ [1, 3] and there are log n levels,
T (n) = Θ(n log n).
Remarks
4log4 n − 1
=n + nlog4 16 .
4−1
This shows that nlog4 16 is the dominant factor and the total contribution from all other
levels is at most the number of leaves.
12
2. Let
n
T (n) = 4T 4 + n.
This satisfies Case 2 of Master’s Theorem and hence, the solution is
From the computation tree, the number of levels is log4 n and each level incurs cost n,
thus
T (n) = Θ(n log n).
Moreover, the contribution from the leaves is just n, which is the same as f (n) = n. Since
the contribution from each level cannot be overlooked in this case, the solution includes
the number of levels and their contribution.
3. Consider
n
+ n2 .
T (n) = 2T 2
In this case, the contribution from each level is cf (n), where c < 1, and the contribution
from the leaves is polynomially smaller than f (n).
This shows that the solution is simply
4. Note that the regularity condition check demands a constant c < 1. If c = 1 or any fixed
value, then the recurrence falls into Case 2. If c > 1 is a constant and increases with
polynomial growth (c, c2 , c3 , . . .) at each stage, then the recurrence falls into Case 1 of
Master’s Theorem.
Then,
logb n−1
X
T (n) = Θ(nlogb a ) + aj f n
bj
.
j=0
Proof:
13
From the recursion tree, it is clear that at level i, there are ai subproblems each of complexity
f (n/bi ). The last level contains the set of leaves and the number of leaves is:
alogb n = nlogb a .
Lemma 2. Let a ≥ 1 and b > 1 be constants, let f (n) be a non-negative function defined
on exact powers of b. Define a function g(n) over exact powers of b by
logb n−1
X
aj f n
g(n) = bj
.
j=0
g(n) = O(nlogb a ).
3. If af (n/b) ≤ cf (n) for some constant c < 1 and for all n ≥ b, then
Proof: Here we analyse the recurrence relation under the simplifying assumption that T (n) is
defined only on exact powers of b > 1, that is, for n = 1, b, b2 , . . .. From Lemma 1,
logb n−1
X
logb a
aj f n
T (n) = Θ(n )+ bj
.
j=0
∞
X 1
g(n) ≤ cj f (n) ⇒ g(n) ≤ f (n) × ⇒ g(n) = O(f (n)).
1−c
j=0
Plogb n−1
Since g(n) = f (n) + j=1 aj f (n/bj ), g(n) > f (n) and g(n) = Ω(f (n)).
14
4.2 Solution using Characteristic Equation Approach
1. an − 7an−1 + 10an−2 = 4n
T (n) − 7T (n − 1) + 10T (n − 2) = 4n
Characteristic equation is x2 − 7x + 10 = 0
(x − 5)(x − 2) = 0; x = 5, 2
Complementary function (C.F.) is c1 5n + c2 2n
Solution is an = c1 5n + c2 2n + Particular integral (P.I.)
For finding P.I., guess an = d4n
d4n − 7d4n−1 + 10d4n−2 = 4n
7d 10d
d− 4 + 16 = 1 ⇒ d = −8
Therefore solution is T (n) = c1 5n + c2 2n − 8 · 4n
2. an − 4an−1 + 4an−2 = 2n
T (n) − 4T (n − 1) + 4T (n − 2) = 2n
Characteristic equation is x2 − 4x + 4 = 0 and the roots are x = 2, 2
Complementary function (C.F.) is c1 2n + c2 n2n
For P.I., note that the guesses d · 2n and d · n2n will not work as the roots and base of the
exponent (non-homogeneous) term are same. Therefore we guess dn2 · 2n .
dn2 2n − 4d(n − 1)2 2n−1 + 4d(n − 2)2 2n−2 = 2n
dn2 − 2d(n2 − 2n + 1) + d(n2 − 4n + 4) = 1
Simplifying we get d = 1
2
n2 n
Therefore T (n) = c1 2n + c2 n2n + 2 2
Theorem 1. Let c1 and c2 be real numbers. Suppose that r2 − c1 r − c2 = 0 has two distinct
roots r1 and r2 . Then the sequence {an } is a solution of the recurrence relation
an = c1 an−1 + c2 an−2
if and only if
an = α1 r1n + α2 r2n , for n = 0, 1, 2, . . . ,
where α1 and α2 are constants.
Proof Sketch:
15
1. First, we prove that, for any constants α1 , α2 , the expression α1 r1n + α2 r2n satisfies the
recurrence relation.
2. Second, we prove that every solution is of the form α1 r1n +α2 r2n . Suppose {an } is a solution
of the recurrence relation with initial conditions a0 = C0 and a1 = C1 . Then, by picking
suitable constants α1 , α2 , we can set the first two values of the sequence α1 r1n + α2 r2n to be
C0 and C1 . Since the sequences {an } and {α1 r1n + α2 r2n } satisfy the degree 2 recurrence
and agree on the first two values, they must be identical.
Example: Find the solution to the recurrence relation an = an−1 + an−2 with initial conditions
a0 = 2 and a1 = 7.
r2 − r − 2 = 0, i.e. (r − 2)(r + 1) = 0.
The roots are 2 and −1. Thus, the solution to the recurrence relation is of the form
an = α1 2n + α2 (−1)n .
a0 = 2 = α 1 + α 2 ,
a1 = 7 = 2α1 − α2 .
Solving, we get α1 = 3 and α2 = −1.
an = c1 an−1 + c2 an−2
if and only if
an = α1 r0n + α2 n · r0n , n = 0, 1, 2, . . . ,
where α1 and α2 are constants. Example: Solve the recurrence relation an = 6an−1 − 9an−2 ,
with initial conditions a0 = 1 and a1 = 6. Solution:
rk − c1 rk−1 − · · · − ck = 0
has k distinct roots r1 , r2 , . . . , rk . Then, a sequence {an } is a solution of the recurrence relation
if and only if
an = α1 r1n + α2 r2n + · · · + αk rkn , n = 0, 1, 2, . . . ,
where α1 , α2 , . . . , αk are constants.
rk − c1 rk−1 − · · · − ck = 0
16
has t distinct roots r1 , r2 , . . . , rt with multiplicities m1 , m2 , . . . , mt respectively, so that mi ≥ 1
for i = 1, 2, . . . , t and m1 + m2 + · · · + mt = k. Then, a sequence {an } is a solution of the
recurrence relation
an = c1 an−1 + c2 an−2 + · · · + ck an−k
if and only if
Problem: Solve the recurrence relation an = −3an−1 − 3an−2 − an−3 with initial conditions
a0 = 1, a1 = −2, a2 = −1.
Solution:
an = (1 + 3n − 2n2 )(−1)n (steps omitted).
where c1 , c2 , . . . , ck are real numbers, and F (n) is a function not identically zero depending only
on n.
17
Let {bn } be an arbitrary solution to the nonhomogeneous recurrence relation. Then,
(p)
Thus, bn − an is a solution to the associated homogeneous recurrence relation with constant
coefficients.
The above theorem gives us a technique to solve nonhomogeneous recurrence relations us-
ing our tools to solve homogeneous recurrence relations. Given a non-homogeneous recurrence
relation, we first guess a particular solution. Note that this satisfies the recurrence equation,
but does not necessarily satisfy the initial conditions. Next, we use the fact that the required
solution to the recurrence relation is the sum of this particular solution and a solution to the
associated homogeneous recurrence relation. We already know a general form for the solution
to the homogeneous recurrence relation (from the previous theorems). This general form will
have some unknown constants and their values can be determined from the fact that the sum
of the particular solution and the homogeneous solution must satisfy the given initial conditions.
Example: Solve the recurrence relation an = 3an−1 + 2n, with initial condition a1 = 3.
Solution:
an = −n − 3
2 + 11
6 · 3n (steps omitted).
Next, we give a systematic way to guess a particular solution for a large class of functions
F (n).
Theorem 6. Suppose that {an } satisfies the linear nonhomogeneous recurrence relation
• When s is not a root of the characteristic equation of the associated linear homogeneous
recurrence relation, there is a particular solution of the form
• When s is a root of this characteristic equation and its multiplicity is m, there is a particular
solution of the form
nm (pt nt + pt−1 nt−1 + · · · + p1 n + p0 )sn .
The above theorem gives a recipe for picking a particular solution to a nonhomogeneous
recurrence relation. The general form of the particular solution has several unknown constants.
Their values can be determined by substituting this general form into the given nonhomogeneous
recurrence relation. This yields a set of equations that can be solved to determine the values of
18
the constants. Substituting the general form yields a single equation. However, this equation
says that a particular expression of the form
t
X
βi fi (n)
i=1
must be identically 0 for all values of n ≥ k. Here βi are linear expressions involving the
unknown constants and fi (n) are functions of n. This then implies that βi = 0 for all i, giving
the required number of equations to determine the unknown constants.
Solution:
an = 12 n2 + 21 n (steps omitted).
Now, the recurrence relation for {an } can be interpreted as an equation for a(x). This allows
us to get a formula for a(x) from which a closed form expression for an can be derived.
Example: Find the generating function for the Fibonacci sequence and derive a closed form
expression for the nth Fibonacci number.
Solution: Let
∞
X
F (x) = fn xn ,
n=0
be the generating function for the Fibonacci sequence. Since the Fibonacci sequence satisfies
the recurrence fn = fn−1 + fn−2 , n ≥ 2, we get an explicit form for F (x) as follows:
∞
X ∞
X ∞
X
n n
fn x = fn−1 x + fn−2 xn
n=2 n=2 n=2
∞
X ∞
X ∞
X
n n 2
fn x = x fn x + x fn xn
n=2 n=1 n=0
F (x)(1 − x − x2 ) = f0 + x(f1 − f0 ) − x
x
F (x) = .
1 − x − x2
To get a closed-form expression for fn , we need to get a closed-form expression for the
coefficient of xn in the expansion of the generating function. To do this, we use the technique
of decomposition into partial fractions:
19
x A B
2
= + ,
(1 − x − x ) x − x1 x − x2
where x1 and x2 are the roots of the polynomial 1 − x − x2 . It is more convenient to express
the generating function in the following form:
x a b
2
= + ,
1−x−x 1 − r1 x 1 − r2 x
where r1 = 1/x1 and r2 = 1/x2 . It turns out that r1 and r2 are the roots of the characteristic
equation (verify this). From this, we can get the closed-form expression
fn = a · r1n + b · r2n .
We can solve for a and b from the fact that the initial conditions must be satisfied and this
will give us the result:
" √ !n √ !n #
1 1+ 5 1− 5
fn = √ − .
5 2 2
The above technique can be generalised to get an expression for the solution of a general
homogeneous recurrence relation with constant coefficients considered in Theorem 4.
rk − c1 rk−1 − · · · − ck = 0
has t distinct roots r1 , r2 , . . . , rt with multiplicities m1 , m2 , . . . , mt respectively, so that mi ≥
1 for i = 1, 2, . .P
. , t and m1 + m2 + · · · + mt = k.
Let a(x) = ∞ n=0 an x be the generating function associated with the sequence {an }. From
n
b0 + b1 x + · · · + bk−1 xk−1
a(x) = .
1 − c1 x − c2 x2 − · · · − ck xk
We express this using partial fractions. First, we factorise the denominator as follows:
b0 + b1 x + · · · + bk−1 xk−1
a(x) =
(1 − r1 x)m1 (1 − r2 x)m2 · · · (1 − rt x)mt
20
A1,0 A1,1 A1,m1 −1
= m
+ m −1
+ · · · +
(1 − r1 x) 1 (1 − r1 x) 1 (1 − r1 x)
A2,0 A2,1 A2,m2 −1
+ m
+ m −1
+ ··· +
(1 − r2 x) 2 (1 − r2 x) 2 (1 − r2 x)
···
Note that this solution is of a slightly different form than the solution claimed in Theorem
4, but the two forms are equivalent, i.e., one form can be converted to the other.
The generating function approach allows us to solve fairly general recurrence relations, as
illustrated below.
Example: Find an explicit formula for the Catalan numbers defined by the recurrence relation
n−1
X
Cn = Ck Cn−1−k
k=0
where C0 = 1.
P∞
Solution: Let C(x) be the generating function n=0 Cn x
n. Then,
n−1
X
Cn = Ck Cn−1−k .
k=0
Multiplying by xn , we get:
n−1
X
Cn xn = xn Ck Cn−1−k
k=0
n−1
X
Cn x n = x (Ck xk ) · (Cn−1−k xn−1−k ).
k=0
Summing this up from n = 1 to ∞, we get:
∞
X ∞ n−1
X X
n
Cn x = x (Ck xk ) · (Cn−1−k xn−1−k ).
n=1 n=1 k=0
21
P∞
Note that C(x) = n=0 Cn x
n. Hence,
C(x) − C0 = xC(x)2 ,
xC(x)2 − C(x) + 1 = 0.
Solving this quadratic equation, we get:
√
1 − 4x
1±
C(x) = .
2x
The generating function is uniquely defined by the recurrence relation and the initial condi-
tion C0 = 1. Hence, we should be able to rule out one of the two possibilities. If we choose the +
sign in the expression for C(x), C(x) → ∞ for x → 0. However, for x → 0, C(x) → C0 = 1. This
rules out the + sign as a valid possibility. Thus, the closed-form expression for the generating
function is
√
1 − 1 − 4x
C(x) = .
2x
Using this, we can obtain a closed-form expression for Cn , the nth Catalan number. We could
certainly do this using the generalised binomial theorem. Here, we give an alternate approach.
We know from a previous exercise that
∞
1 X 2n n
√ = t
1 − 4t n=0 n
√ ∞
1− 1 − 4x X 1 2n n
= x
2x n+1 n
n=0
22