Data Structures, Algorithms, & Applications in C++
CHAPTER 53 _________ RECURRENCE EQUATIONS This material is essentially Chapter 7 of the book Concepts in Discrete Mathematics by Sartaj Sahni, Camelot Publishing, 1985. It is reproduced here with permission of the publisher. INTRODUCTION
The computing time of an algorithm (particularly a recursive algorithm) is ofteneasily expressed recursively (i.e., in terms of itself). This was the case, forinstance, for the function
rSum (Program 1.26). We had determined that
trSum (n) = c +trSum (n −1) where c is some constant. The worst-case computing
, of the merge sort method is easily seen to satisfy the inequality:
M ( n /2 )+tM ( n /2 )+c 4 n n >1
2 Chapter 53 Recurrence Equations
We expect the recurrence (53.1) to be difficult to solve because of the pres-
ence of the ceiling and floor functions. If we attempt to solve (53.1) only forvalues of n that are a power of 2 (n =2k), then (53.1) becomes:
M (n /2)+c 4 n n >1 and a power of 2
If the inequality of (53.2) is converted to the equality:
2t´M(n /2)+c 4n n>1 and a power of 2M (n ) is an upper bound on tM (n ). So, if tM (n) = f (n) then tM (n) = Ο(f (n )).
Since it is also the case that there exist constants c 5 and c 6 such that:
M (n /2)+c 6 n n>1 and n a power of 2M (n ) = Ω(f (n)). Hence, tM (n ) = Θ( f (n )).
The entire discussion concerning the worst case complexity tw
repeated with respect to the best case complexity (i.e. the minimum time spenton any input of n numbers). The conclusion is that tbM(n) = Θ(f (n)). Since boththe best and worst case complexities are Θ(f (n)), it follows that taM(n) = Θ(f (n))and tM(n) = Θ(f (n)).
when analyzing quick sort, we see that the partitioning into left (L) and
right (R) segments can be done in Θ(n) time. So,
c 2+tQ( | L | )+tQ( | R | ) n >1
In (53.4), Q has been used as an abbreviation for QuickSort . | L | can be anynumber in the range 0 to n −1. For random instances, | L | equals each of 0, 1, .,n −1 with equal probability. So, for the average complexity of QuickSort ,we obtain:
[tQ(i)+tQ(n −i))] n >1
Section 53.1 Introduction 3
The worst case for QuickSort is when one of L and R is empty at all
levels of the recursion. In this case, we obtain the recurrence:
2 n +tQ (n −1) n >1
The best case for QuickSor is when | L | ≈ | R | at all levels of the recursion. The recurrence for this case is:
A function g (n) such that tbQ(n) = Θ(g (n)) for n a power of 2 can be obtained bysolving the recurrence:
2 n+2tQ (n /2) n>1 and a power of 2
For select (Program 19.8), the worst case is when k = 1 and | R | = 0 at
all levels of the recursion. So, the worst-case computing time of select isgiven by the recurrence:
2 n +tselect (n −1) n >1
To obtain the recurrence for the average computing time of select, we
need to introduce some new functions. First, we shall assume that all the ele-ments are distinct. Let t k(n) be the average time to find the kth smallest element. This average is taken over all n! permutations of the elements. The averagecomputing time of select is given by:
Define R (n) to be the largest t k(n). That is,
R (n) = max {t k(n)}
4 Chapter 53 Recurrence Equations
It is easy to see that taselect (n) ≤ R (n).
With these definitions in mind, let us proceed to analyze select for the
case when all elements are distinct. For random input, there is an equal probabil-ity that | L | = 0, 1, 2, ., n −1. This leads to the following inequality for t k(n):
[ Σ tk(j −1)+ Σ tk−j(n −j)] n ≥2
R (n) ≤ cn+ max{ Σ R (j −1) + Σ R (n −j)}, n≥2
Since R is an increasing function of n,
If R (n) = Θ(f (n)), then it follows from our earlier observation
select (n ) ≤ R (n)) that tselect (n ) = Ο(f (n)). We shall later see that R (n) = Θ(n).
This together with the observation taselect (n) = Ω(n) leads to the conclusion thattaselect (n) = Θ(n).
Even though binarySearch (Program 3.1) is not a recursive algorithm,
its worst-case time complexity is best described by a recurrence relation. It is nottoo difficult to see that the following recurrence is correct:
Section 53.1 Introduction 5
When n is a power of 2, (53.11) simplifies to:
2 +tB (n /2) n>1 and a power of 2
Hopefully, these examples have convinced you that recurrence relations
are indeed useful in describing the time complexity of both iterative and recur-sive algorithms. In each of the above examples, the recurrence relations them-selves were easily obtained. Having obtained the recurrence, we must now solveit to determine the asymptotic growth rate of the time complexity. We shall con-sider four methods of solving recurrence relations:
(a) substitution(b) induction(c) characteristic roots(d) generating functions. SUBSTITUTION
In the substitution method of solving a recurrence relation for f(n), the recurrencefor f (n) is repeatedly used to eliminate all occurrences of f () from the righthand side of the recurrence. Once this has been done, the terms in the right handside are collected together to obtain a compact expression for f (n). Themechanics of this method are best described by means of examples. Example 53.1 Consider the recurrence: c 2+t (n −1) n ≥1
When c 1 = c 2 = 2, t (n) is the recurrence for the step count of rSum (Program1.9). If n > 2 then t (n −1) = c 2+t (n −2). If n > 3 then t (n −2) = c 2+t (n −3) etc. These equalities are immediate consequences of (53.13) and are used in the fol-lowing derivation of a nonrecursive expression for t (n):
= c 2+c 2+c 2+t(n-3). . . 6 Chapter 53 Recurrence Equations
So, we see that t (n) = c 2n+c 1, n ≥ 0. From this, we obtain trSum(n) = 2n+2. Example 53.2 Recurrence (53.12) may be solved by substitution. Observe that (53.12) defines tw B (n ) only for values of n that are a power of 2. If n is not a power
of 2, then the value of t (n) is not defined by (53.12). For example, if n = 5 thentwB (2.5) appears on the right hand side of (53.12). But tB is a function whose
domain is the natural numbers. If n = 6, then from (53.12) we obtain (t is used asan abbreviation for tw
But, t(1.5) is undefined. When n is a power of 2, t(n) is always defined (i.e.,using the recurrence 7.12). t (n) is of course defined for all n∈N-{1} when(53.11) is used. Assuming n is a power of 2 (say, n = 2k), the substitution methodleads to the following series of equalities:
t (n) = c 2 + t (n /2)
= c 2 +c 2 +t (n /4)
= c 2 +c 2 +c 2 +t (n /8). . . = kc 2 +t (n /2k)
= c 1 +c 2logn, n a power of 2
Unless otherwise specified, all logarithms in this chapter are base 2. At thispoint, we only have an expression for twB (n) for values of n that are a power of 2.
If n is between 2k and 2k +1, then twB (n) will be between t(2k ) and t(2k +1 ). So,
1 +c 2 logn ≤tB c 1 +c 2 log n
for all n. This implies that tB(n) = Θ(log n). Example 53.3 Consider the recurrence: a*t (n /b)+cn n ≥2
Section 53.2 Substitution 7
This recurrence defines t (n) only for values of n that are a power of b. Therecurrence (53.3) is the same as (53.14) when c 1 = c 4 = c, and a = b = 2. Eventhough (53.3) is not an instance of (53.14) (as c ≠
(53.14) with a = 2 and b = 2 does give us a function g(n) such that t´M(n) =
Ο(g(n)). And, from the discussion following (53.3) it should be clear that twM(n) =
Θ(g(n)). When c = c1, and a = b = 2, (53.14) becomes the same as (53.8).
Assume that n = b k for some natural number k. Solving (53.14) by the sub-
= a 2[a*t(n/b 3)+c(n/b 2)]+cn[a/b+1]
= a 3t(n/b 3)+cn(a 2/b 2)+cn[a/b+1]
= a 3[a*t(n/b 4)+c(n/b 3)]+cn[a 2/b 2+a/b+1]
= a 4t(n/b 4)+cn[a 3/b 3+a 2/b 2+a/b+1]. . .
(a /b)i, (b k = b
= cn Σk (a /b)i.
When a = b, Σk(a /b)i = k+1. When a ≠ b, Σk (a /b)i = ((a /b)k+1-1)/(a/b-1). If a<b
then a/b<1 and ((a /b)k +1-1)/(a/b-1) = (1-(a /b)k +1)/ (1-a/b)<1/(1-a/b). 8 Chapter 53 Recurrence Equations
(a /b)i = Θ(1). When a>b, ((a /b)k +1-1)/(a/b-1) = Θ((a /b)k) = Θ(a k/bt (n) = Θ(nlogn) a =b
From this and our earlier discussion, we conclude that tw
Recurrence (53.14) is a very frequently occurring recurrence form in the
analysis of algorithms. It often occurs with the cn term replaced by such termsas c, or cn 2, or cn 3 etc. So, we would like to extend the result of Example 53.3and obtain a general form for the solution of the recurrence:
t (n) =a*t (n /b)+g (n),n ≥ b and napower ofb,
where a and b are known constants. We shall assume that t(1) is also known. Clearly, (53.15) reduces to (53.14) when t(1)= c and g(n) = cn. Using the substi-tution method, we obtain:
= a 2t(n/b 2)+ag(n/b)+g(n). . .
where k = logbn. This equation may be further simplified as below:
= a k[t (1)+ Σk a−jg (b j)]
Section 53.2 Substitution 9 b a , the expression for t (n) becomes:
b a [t(1)+ Σk a−j g(b j)]
b a [t(1)+ Σk {g (b j)/(b j) ba}]
b a [t(1)+ Σk h (b j)]
b a [t (1)+f (n)]
where f (n) = Σk h (b j) and h(n) = g(n)/n ba. Figure 53.1 tabulates the asymp-
totic value of f (n) for various h(n)s. This table together with (53.16) allows oneto easily obtain the asymptotic value of t (n) for many of the recurrences oneencounters when analyzing algorithms.
Θ(((logn)i+1)/(i +1))
Figure 53.1 f (n) values for various h(n) values.
Let us consider some examples using this table. The recurrence for tw
and t(1) = c 1. Comparing with (53.15), we see that a=1, b=2, and g(n) = c 2. So,
b (a) = 0 and h(n) = g(n)/n
= c 2 = c 2(logn)0 = Θ((logn)0). From ?F7.1},
we obtain f (n) = Θ(log n). So,
10 Chapter 53 Recurrence Equations
t(n) = 7t(n/2)+18n 2, n≥2 and n a power of 2,
we obtain: a=7, b=2, and g(n) = 18n 2. So, logba = log27 ≈ 2.81 and h(n) =
= Ο(n r) where r = 2-log27 < 0. So, f (n) = Ο(1). The
as t(1) may be assumed to be constant.
As a final example, consider the recurrence:
t(n) = 9t(n/3)+4n 6, n ≥ 3 and a power of 3.
Comparing with (53.15), we obtain a=9, b=3, and g(n) = 4n 6. So, logba = 2 andh(n) = 4n 6/n 2 = 4n 4 = Ω(n 4). From Figure 53.1, we see that f (n) = Θ(h(n)) =
INDUCTION
Induction is more of a verification method than a solution method. If we have anidea as to what the solution to a particular recurrence is then we can verify it byproviding a proof by induction. Example 53.4 Induction can be used to show that t (n) = 3n+2 is the solution to the recurrence:
For the induction base, we see that when n=0, t (n) = 2 and 3n+2 = 2. Assumethat t (n) = 3n+2 for some n, n = m. For the induction step, we shall show that
Section 53.3 Induction 11 t (n) = 3n+2 when n = m+1. From the recurrence for t(n), we obtain t(m+1) =3+t(m). But from the induction hypothesis t(m) = 3m+2. So, t(m+1) = 3+3m+2= 3(m+1)+2. Example 53.5 Consider recurrence (53.10). We shall show that R(n)<4cn, n≥1. Induction Induction Hypothesis: Let m be an arbitrary natural number, m≥3. Assume that R(n)<4cn for all n, 1≤n<m. Induction Step: For n = m and m even, (53.10) gives:
Since R(n)<4cn, R(n) = Ο(n). Hence, the average computing time of procedureselect is Ο(n). Since procedure select spends at least n units of time oneach input of size n, taselect (n) = Ω(n). Combining these two, we get tselect (n) =
Example 53.6 Consider recurrence (53.9). Let t (n) denote tW
2 n(n +1) / 2+c 1 c 2 = Θ(n 2 ). Induction Base: When n = 1, (53.9) yields t (n) = c
1 . Also, c 2 n (n +1) / 2+c 1 c 2
Induction Hypothesis: Let m be an arbitrary natural number. Assume that t (n) 12 Chapter 53 Recurrence Equations
2 n (n +1) / 2+c 1 c 2 when n = m. Induction Step: When n = m +1, (53.9) yields: t (m +1)=c 2(m +1)+t (m)
2 (m +1)+c 2 m (m +1) / 2+c 1 c 2 (from the IH)
2 (m +1)+c 2 m(m +1)] / 2+c 1 c 2
2 (m +1)(m +2) / 2+c 1 c 2 .
As mentioned earlier, the induction method cannot be used to find the solu-
tion to a recurrence equation; it can be used only to verify that a candidate solu-tion is correct. CHARACTERISTIC ROOTS
The recurrence equation of f (n) is a linear recurrence iff it is of the form: f (n) = Σk gi(n)f (n − i) +g (n)
where the gi(n), 1 ≤ i ≤ k and g (n) are functions of n but not of f. A linear recurrence is of order k iff it is of the form given above, k is a constant, and gk(n) is not identically equal to zero. If gk(n) is zero for all n, then the order of the recurrence is less than k. A linear recurrence of order k is of constant coefficients iff there exists constants a 1, a 2, . . . , ak such that gi(n) = ai, 1 ≤ i ≤ k. In this section, we are concerned only with the solution of linear recurrences of order k that have constant coefficients. These recurrences are of the form: f (n) =a 1 f (n − 1) +a 2 f (n − 2) + . . . +ak f (n − k) +g (n), n ≥ k
where ak ≠ 0 and g (n) is a function of n but not of f. (53.17) is a homogeneous recurrence iff g (n) = 0. One may readily verify that for any set f (0), f (1), . . . , f (k − 1) of initial values, the recurrence (53.17) uniquely determines f (k),f (k+ 1), . . . .
Many of the recurrence equations we have considered in this book are
linear recurrences with constant coefficients. Using t (n) to denote t´M, (53.3)takes the form:
2t(n /2)+c 4n n>=2 and a power of 2
This isn’t a linear recurrence of order k for any fixed k because of the occurrenceof t (n / 2) on the right side. However, since n is a power of 2, (53.18) may be
Section 53.4 Characteristic Roots 13
2t(2k − 1)+c 42k k ≥1
Using h (k) to denote t (2k), (53.19) becomes:
2h(k − 1)+c 42k k ≥1
Recurrence (53.20) is readily identified as a linear recurrence with constatntcoefficients. It is of order 1 and it is not homogeneous. Since h (k) = t (2k) = t (n)for n a power of 2, solving (53.20) is equivalent to solving (53.3).
Recurrence (53.5) is a linear recurrence. However, it is not of order k for
any fixed k. By performing some algebra, we can transform this recurrence intoan order 1 linear recurrence. We use t (n) as an abbreviation for taQ(n). With this,(53.5) becomes (for n> 1):
t (n) =c 2n+
Multiplying (53.21) by n, we obtain:
nt (n) =c 2n 2 + 2 Σ
Substituting n − 1 for n in (53.22), we get:
(n − 1)t (n − 1) =c 2(n − 1)2 + 2 Σ
nt (n) − (n − 1)t (n − 1) = (2n − 1)c 2 + 2t (n − 1)
nt (n) = (2n − 1)c 2 + (n+ 1)t (n − 1)
14 Chapter 53 Recurrence Equations t (n − 1) + (2 − )c 2
Even though (53.24) is not a linear recurrence with constant coefficients, it
can be solved fairly easily. Recurrence (53.8) can be transformed into anequivalent constant coefficient linear recurrence of order 1 in much the same wayas we transformed (53.3) into such a recurrence. (53.9) is already in the form of(53.17). The recurrence:
F (n) =F (n − 1) +F (n − 2), n ≥ 2
defines the Fibonacci numbers when the initial values F (0) = 0 and F (1) = 1 areused. This is an order 2 homogeneous constant coefficient linear recurrence.
Linear recurrences of the form (53.17) occur frequently in the analysis of
computer algorithms, particularly in the analysis of divide-and-conquer algo-rithms. These recurrences can be solved by first obtaining a general solution for
f (n). This general solution caontains some unspecified constants and has the
property that for any given set f (0), f (1), . . . , f (k − 1) of initial values, we canassign values to the unspecified constants such that the general solution definesthe unique sequence f (0), f (1), . . . .
Consider the recurrence f (n) = 5f (n − 1) − 6f (n − 2), n ≥ 2. Its general
solution is f (n) =c 12n+c 23n (we shall soon see how to obtain this). Theunspecified constants are c 1 and c 2. If we are given that f (0) = 0 and f (1) = 1,then we substitute into f (n) = c 12n+c 23n to determine c 1 and c 2. Doing this,we get:
f (0) =c 1 +c 2 = 0 and f (1) = 2c 1 + 3c 2 = 1
Solving for c 1 and c 2, we get c 1 = −c 2 = −1. Therefore, f (n) = 3n − 2n, n ≥ 0, isthe solution to the recurrence f (n) = 5f (n − 1) − 6f (n − 2), n ≥ 2 when f (0) = 0and f (1) = 1. If we change the initial values to f (0) = 0 and f (1) = 10, then weget:
f (0) =c 1 +c 2 = 0 and f (1) = 2c 1 + 3c 2 = 10
Solving for c 1 and c 2, we get c 1 = −c 2 = −10. Therefore, f (n) = 10(3n − 2n),n ≥ 0.
The general solution to any recurrence of the form (53.17) can be
represented as the sum of two functions fh(n) and fp(n); fh(n) is the general solu-tion to the homogeneous part of (53.17):
fh(n) =a 1 fh(n − 1) +a 2 fh(n − 2) + . . . +ak fh(n − k)
and fp(n) is a particular solution for:
Section 53.4 Characteristic Roots 15 fp(n) =a 1 fp(n − 1) +a 2 fp(n − 2) + . . . +ak fp(n − k) +g (n)
While at first glance it might seem sufficient to determine fp(n), it should be
noted that fp(n) +fh(n) is also a solution to (53.17). Since the methods used todetermine fp(n) will give us an fp(n) form that does not explicitly contain all
zeroes of f (n) (i.e., all solutions to f (n) − Σk ai f (n − i) = 0), it is necessary to
determine fh(n) and add it to fp(n) to get the general solution to f (n). Solving For fh(n)
To determine fh(n) we need to solve a recurrence of the form:
fh(n) =a 1 fh(n − 1) +a 2 fh(n − 2) + . . . +ak fh(n − k)
fh(n) − a 1 fh(n − 1) − a 2 fh(n − 2) − . . . − ak fh(n − k) = 0
We might suspect that (53.25) has a solution of the form fh(n) = Ax n. Sub-
A (x n − a 1x n −1 − a 2x n − 2 − . . . − akx n − k) = 0
We may assume that A ≠ 0. So we obtain:
x n − k(x k − Σk aixk −i) = 0
The above equation has n roots. Because of the term x n − k, n − k of these rootsare 0. The remaining k roots are roots of the equation:
x k − a 1x k −1 − a 2x k − 2 − . . . − ak= 0
(53.26) is called the characteristic equation of (53.25). From elementary
polynomial root theory, we know that (53.26) has exactly k roots r 1, r 2, . . . , rk. x 2 − 5x+ 6 = 0
are r 1 = 2 and r 2 = 3. The characteristic equation
16 Chapter 53 Recurrence Equations x 3 − 8x 2 + 21x − 18 = 0
has the roots r 1 = 2, r 2 = 3, and r 3 = 3. As is evident, the roots of a characteris- tic equation need not be distinct. A root ri is of multiplicity j iff ri occurs j times in the collection of k roots. Since the roots of (53.27) are distinct, all have multiplicity 1. For (53.28), 3 is a root of multiplicity 2, and the multiplicity of 2 is 1. The distinct roots of (53.28) are 2 and 3. Theorem 53.1 tells us how to determine the general solution to a linear homogeneous recurrence of the form (53.25) from the roots of its characteristic equation. Theorem 53.1 Let the distinct roots of the characteristic equation: x k − a 1x k −1 − a 2x k − 2 − . . . − ak= 0
fh(n) =a 1 fh(n − 1) +a 2 fh(n − 2) + . . . +ak fh(n − k)
be t 1, t 2, . . . , ts, where s ≤ k. There is a general solution fh(n) which is of theform:
fh(n) =u 1(n) +u 2(n) + . . . +us(n)
i (n) = (ci +c n +c n 2 + . . . +c
Here, w is the multiplicity of the root ti. Proof See the references for a proof of this theorem.
The characteristic equation for the recurrence
f (n) = 5f (n − 1) − 6f (n − 2), n ≥ 2
x 2 − 5x+ 6 = 0
The roots of this characteristic equation are 2 and 3. The distinct roots are t 1 = 2and t 2 = 3. From Theorem 53.1 it follows that f (n) = u 1(n) +u 2(n), whereu 1(n) = c 12n and u 2(n) = c 23n. Therefore, f (n) = c 12n+c 23n. Section 53.4 Characteristic Roots 17
(53.28) is the characteristic equation for the homogeneous recurrence:
f (n) = 8f (n − 1) − 21f (n − 2) + 18f (n − 3)
Its distinct roots are t 1 = 2 and t 2 = 3. t 2 is a root of multiplicity 2. So, u 1(n) =c 12n, and u 2(n) = (c 2 +c 3n)3n. The general solution to the recurrence is f (n) =c 12n+ (c 2 +c 3n)3n.
The recurrence for the Fibonacci numbers is homogeneous and has the
characteristic equation x 2 − x − 1 = 0. Its roots are r 1 = (1 + √5 ) / 2 and r 2 =(1 − √5 ) / 2. Since the roots are distinct, u 1(n) = c 1((1 + √5 ) / 2)n and u 2(n) =c 2((1 − √5 ) / 2)n. Therefore
is a general solution to the Fibonacci recurrence. Using the initial values F(0) = 0and F(1) = 1, we get c 1+c 2 = 0 and c 1(1+5)/2+c 2(1-5)/2 = 1. Solving for c 1 andc 2, we get c 1 = -c 2 = 1/5. So the Fibonacci numbers satisfy the equality:
Theorem 53.1 gives us a straightforward way to determine a general solu-
tion for an order k linear homogeneous recurrence with constant coefficients. Weneed only determine the roots of its characteristic equation. Solving For fp (n)
There is no known general method to obtain the particular solution fp(n). Theform of fp(n) depends very much on the form of g(n). We shall consider onlytwo cases. One where g(n) is a polynomial in n and the other where g(n) is anexponential function of n.
When g(n) = 0, the particular solution is fp(n) = 0.
0, the particular solution is of the form:
fp(n) =p 0+p 1n+p 2n 2 + . . . +pd +mn d +m
where m = 0 if 1 is not a root of the characteristic equation corresponding to thehomogeneous part of (53.17). If 1 is a root of this equation, then m equals themultiplicity of the root 1. 18 Chapter 53 Recurrence Equations
To determine p 0, p 1, ., pd +m, we merely substitute the right hand side of
(53.29) into the recurrence for fp( ); compare terms with like powers of n on theleft and right hand side of the resulting equation and solve for p 0, p 1, p 2, .,pd +m. f (n) = 3f (n −1) + 6f (n −2) + 3n+ 2
g(n) = 3n+2. The characteristic equation is x 2-3x-6 = 0. 1 is not one of its roots. So, the particular solution is of the form:
fp (n) =p 0 +p 1 np 0+p 1n = 3(p 0 +p 1 (n −1)) + 6(p 0 +p 1 ∗ (n −2)) + 3n+ 2
= 3p 0 + 3p 1n − 3p 1 + 6p 0 + 6p 1 n − 12p 1 + 3n+ 2
= (9p 0 − 15p 1 + 2) + (9p 1 + 3)n
Comparing terms on the left and right hand sides, we see that:
So, p 1 = -3/8 and p 0 = -61/64. The particular solution for (53.30) is therefore:
f (n) = 2f (n − 1) − f (n − 2) − 6
The corresponding characteristic equation is x 2−2x +1 = 0. Its roots are r 1 = r 2= 1. So, fp(n) is of the form:
fp(n) =p 0 +p 1n+p 2n 2
Section 53.4 Characteristic Roots 19 p 0+p 1n+p 2n 2
2(p 0+p 1n-p 1+p 2(n 2-2n+1))-p 0-p 1n+2p 1-
= (2p 0-2p 1+2p 2-p 0+2p 1-4p 2-6)+(2p 1-4p 2-p 1+4p 2)n+p 2n 2
= (p 0-2p 2-6)+p 1n+p 2n 2
So, fp(n) = p 0+p 1n-3n 2. fh(n) = (c 0+c 1n)(1)n. So, f (n) = c 0+c 1n+p 0+p 1n-3n 2= c 2+c 3n-3n 2. c 2 and c 3 can be determined once the intial values f(0) and f(1)have been specified.
When g(n) is of the form ca n where c and a are constants, then the particu-
lar solution fp(n) is of the form:
fp(n) =(p 0 +p 1n+p 2n 2 + . . . +pwn w)a n
where w is 0 if a is not a root of the characteristic equation corresponding to thehomogeneous part of (53.17) and equals the multiplicity of a otherwise. f (n) = 3f (n −1) + 2f (n −4) − 6 ∗ 2n
The corresponding homogeneous recurrence is:
fh(n) = 3fh(n-1)+2fh(n-4)
We may verify that 2 is not a root of this equation. So, the particular solution to(53.32) is of the form:
Substituting this into (53.32), we obtain:
p 02n = 3p 02n −1+2p 02n −4-6*2n20 Chapter 53 Recurrence Equations
Dividing out by 2n −4, we obtain:
16p 0 = 24p 0+2p 0-96 = 26p 0-96
So, p 0 = 96/10 = 9.6. The particular solution to (53.32) is fp(n) = 9.6*2n
The characteristic equation corresponding to the homogeneous part of the
f (n) = 5f (n −1) − 6f (n −2) + 4 ∗ 3n
is x 2 − 5x+ 6 = 0. Its roots are r 1 = 2 and r 2 = 3. Since 3 is a root of multipli-city 1 of the characteristic equation, the particular solution is of the form:
fp(n) = (p 0+p 1n)3n. p 03n+p 1n 3n= 5(p 0+p 1(n −1))3n −1-6(p 0+p 1(n-2))3n −2+4*3n
9p 0+9p 1n = 15p 0+15p 1n-15p 1-6p 0-6p 1n+12p 1+36
= (9p 0-3p 1+36)+9p 1n
These equations enable us to determine that p 1 = 12. The particular solution to(53.33) is:
fp(n) = (p 0+12n)3nfh(n) = c 12n+c 23nSection 53.4 Characteristic Roots 21
The general solution for f (n) is therefore:
= c 12n+(c 2+p 0)3n+12n3n
= c 12n+c 33n+12n3n
Given two initial values, f(0) and f(1), we can determine c 1 and c 3. Obtaining The Complete Solution
We know that fh(n)+fp(n) is a general solution to the recurrence:
f (n) =a 1 f (n−1)+a 2 f (n−2)+ . . . +ak f (n−k)+g (n), n ≥ k
By using the initial values f(0), f(1), ., f(k-1), we can solve for the k undeter-mined coefficients in fh(n) + fp(n) to obtain the unique solution of (53.34) forwhich f(0),.,f(k-1) have the given values.
The characteristic roots method to solve the linear recurrence (53.34) consists ofthe following steps:
x k − Σk aixk−i= 0
Determine the distinct roots t 1, t 2, ., ts of the characteristic equation. Determine the multiplicity mi of the root ti, 1≤i≤s.
Write down the form of fh(n). I.e.,
fh(n) =u 1(n) +u 2(n) + . . . +us(n)
i (n ) = (ci +c n+c n 2 + . . . +c
and w = mi = multiplicity of the root ti. 22 Chapter 53 Recurrence Equations
Obtain the form of the particular solution fp(n). (a)
fp(n) =p 0 +p 1n+p 2n 2 + . . . +pd +mn d +m
where m = 0 if 1 is not a root of the characteristic equation. m is themultiplicity of 1 as a root of the characteristic equation otherwise. fp(n) = (p 0 +p 1n+p 2n 2 + . . . +pwn w)a n
where w is zero if a is not a root of the characteristic equation. If a isa root of the characteristic equation, then w is the multiplicity of a.
If g(n) ≠ 0, then use the fp(n) obtained in (4) above to eliminate alloccurrences of f(n-i), 0≤i≤k from (53.34). This is done by substituting thevalue of fp(n-i) for f(n-i), 0≤i≤k in (53.34). Following this substitution, asystem of equations equating the coefficients of like powers of n isobtained. This system is solved to obtain the values of as many of the pisas possible.
Write down the form of the answer. I.e., f (n) = fh(n)+fp(n). Solve for theremaining unknowns using the initial values f(0), f(1), ., f(k-1). Theorem 53.2 The six step procedure outlined above always finds the unique solution to (53.34) with the given initial values. Proof See the text by Brualdi that is cited in the reference section. EXAMPLES Example 53.7 The characteristic equation for the homogeneous recurrence:
Its roots are r 1 = 3+√5 and r 2 = 3-√5 . The roots are distinct and so t (n) =c 1(3+√5 )n+c 2(3−√5 )n. Suppose we are given that t(0) = 0 and t(1) = 4√5 . Section 53.4 Characteristic Roots 23
Substituting n = 0 and 1 into t(n), we get:
The first equality yields c 1 = -c 2. The second then gives us 45 = c 1(3+5-3+5) =25c 1 or c 1 = 2. The expression for t(n) is therefore: t (n) = 2(3+5)n - 2(3-5)n,n≥0. Example 53.8 In this example we shall obtain a closed form formula for the sum
s(n) = Σn i. The recurrence for s(n) is easily seen to be:
Its characteristic equation is x-1 = 0. So, sh(n) = c 1(1)n = c 1. Since g(n) = n and1 is a root of multiplicity 1, the particular solution is of the form:
sp(n) = p 0+p 1n+p 2n 2
Substituting into the recurrence for s(n), we obtain:
p 0+p 1n+p 2n 2 = p 0+p 1(n−1)+p 2(n −1)2+n
= p 0+p 1n−p 1+p 2n 2−2p 2n+p 2+n
0 p 1 +p 2 ) + (p 1 2p 2 +1)n+p 2 n 2
Equating the coefficients of like powers of n and solving the resulting equations,we get p 1 = p 2, and 2p 2 = 1 or p 2 = 1/2. The particular solution is sp(n) =p 0+n /2+n 2/2 The general solution becomes s(n) = (c 1+p 0) +n /2 +n 2/2. Since s(0) = 0, c 1+p 0 = 0. Hence, s(n) = n(n+1)/2, n≥0. Example 53.9 Consider the recurrence:
f(n) = 5f(n-1) - 6f(n-2) + 3n 2, n≥2
24 Chapter 53 Recurrence Equations
The characteristic equation for the homogeneous part is:
Its roots are r 1 = 2 and r 2 = 3. The general solution to the homogeneous part istherefore:
fh(n) =c 12n+c 23n .
Since g(n) = 3n 2 and 1 is not a root of the characteristic equation, the particularsolution has the form:
fp(n) =p 0+p 1n+p 2n 2
Substituting into the recurrence for f( ), we obtain:
p 0+p 1n+p 2n 2
= 5(p 0+p 1(n −1)+p 2(n −1)2) − 6(p 0+p 1(n−2)+p 2(n−2)2) + 3n 2
1 p 0 19p 2 ) + (14p 2 p 1 )n+ (3−p 2 )n 2
p 0 = 7p 1-p 0-19p 2
Hence, p 2 = 1.5, p 1 = 7p 2 = 10.5, and p 0 = 22.5. So, the general solution for
f(n) = c 12n+c 23n+ 22.5 + 10.5n+ 1.5n 2
Since f(0) and f(1) are known to be 2.5 and 4.5, respectively, we obtain:
2.5 = c 1 +c 2 + 22.5
4.5 = 2c 1 + 3c 2 + 34.5
Solving for c 1 and c 2, we get: c 1 = -30 and c 2 = 10. The solution to our
Section 53.4 Characteristic Roots 25
f(n) = 22.5 + 10.5n + 1.5n 2 - 30*2n + 10*3n. Example 53.10 Let us solve the recurrence:
f(n) = 10f(n-1)-37f(n-2)+60f(n-3)-36f(n-4)+4, n≥4
x 4−10x 3+37x 2−60x+36 = 0
(x−2)2(x−3)2 = 0
The four roots are r 1 =r 2 = 2, and r 3 = r 4 = 3. Since each is a root of multipli-city 2, u 1(n) = (c 1+c 2n)2n and u 2(n) = (c 3+c 4n)3n. The solution to the homo-geneous part is:
fh(n) = (c 1+c 2n)2n+ (c 3+c 4n)3n
Since g(n) = 4 = 4*n 0 and 1 is not a root of the characteristic equation, fp(n) is ofthe form:
Substituting into the recurrence for f(n), we get:
0 = 10p 0 37p 0 +60p 0 36p 0 +4
The general solution for f (n) is:
f(n) = (c 1+c 2n)2n+ (c 3+c 4n)3n + 1
Substituting for n = 0, 1, 2, and 3, and using f(0) = f(1) = f(2) = f(3) = 1, we get:
26 Chapter 53 Recurrence Equations
0 =c 1 +c 3
0 = 2c 1 + 2c 2 + 3c 3 + 3c 4
0 = 4c 1 + 8c 2 + 9c 3 + 18c 4
0 = 8c 1 + 24c 2 + 27c 3 + 81c 4
Solving for c 1, c 2, c 3, and c 4, we obtain c 1 = c 2 = c 3 = c 4 = 0. So, f (n) = 1,n≥1.
We may verify that f (n) = 1, n≥0 does indeed satisfy the given recurrence.
We proceed by induction. For the induction base, we need to show that f (n) = 1,0≤n≤3. This is true by definition of f(). So, let m be an arbitrary natural numbersuch that m≥3. Assume f (n) = 1, for n≤m. When n = m+1, f(m+1) = 10f(m) -37f(m-1) + 60f(m-2) - 36f(m-3) + 4 = 10-37+60-36+4 = 1.
Let us change the initial values to f(0) = f(1) = f(2) = 1, and f(3) = 4. Now,
only equation (53.35d) changes. It becomes:
3 = 8c 1 + 24c 2 + 27c 3 + 81c 4
Solving (53.35 a to c) and (53.35e) for c 1, c 2, c 3, and c 4, we obtain c 1 = 6, c 2 =1.5, c 3 = -6, and c 4 = 1. So,
f (n) = (6+1.5n)2n+ (n −6)3n 1, n ≥ 0
Once again, one may verify the correctness of this formula using induction on n. Solving Other Recurrences
Certain non-linear recurrences as well as linear ones with non constantcoefficients may also be solved using the method of this section. In all cases, weneed to first perform a suitable transformation on the given recurrence so as toobtain a linear recurrence with constant coefficients. For example, recurrences ofthe form:
f c(n) = Σk ai fc(n −i) +g (n), n≥k
may be solved by first substituting f c(n) = q(n) to obtain the recurrence:
q (n) = Σk aiq (n −i) +g (n), n≥k
Section 53.4 Characteristic Roots 27
This can be solved for q(n) as described earlier. From q(n) we may obtain f (n)by noting that f (n) = (q (n))1/c. nf (n) = Σk (n −i)ai f (n −i) +g (n), n≥k
may be solved by substituting q(n) = nf(n) to obtain:
q (n) = Σk aiq (n −i) +g (n), n≥k
Since f (n) = q(n)/n, f (n) is determined once q(n) is. GENERATING FUNCTIONS
A generating function G(z) is an infinite power series
G (z) = Σ cizi
We shall say that the generating function G (z) corresponds to the function f: N -> R iff ci = f(i), i≥0. Example 53.11 G(z) = Σ2zi generates the function f (n) = 2, n≥0; G(z) = Σizi
generates the function f (n) = n, n≥0; G(z) = Σ2zi generates the function:
A generating function may be specified in two forms. One of these is
called the power series form. This is the form given in equation (53.36). Theother form is called the closed form. In this form there are no occurrences of thesymbol Σ. Example 53.12 The power series form for the generating function for f (n) = 1, n≥0 is G(z) = Σzi. So, zG(z) = Σzi. Subtracting, we obtain: G(z) - zG(z) = z i − Σzi = 1. So, G(z) =
. The closed form for the power series Σzi is
28 Chapter 53 Recurrence Equations
= Σzi only for those values of z for which the series Σzi
converges. The values of z for which this series converges are not relevant toour discussion here. Example 53.13 Let n be an integer and i a natural number. The binomial i (i −1)(i −2).(1)
A more general form of the binomial theorem is:
where m = n if n ≥ 0 and m = ∞ otherwise.
(53.37) leads us to some important closed forms. When n = -2, we obtain:
______ = Σ(−1)i(i+1)ziSection 53.5 Generating Functions 29
Substituting −z for z in (53.38), we obtain:
is the closed form for Σ(i +1)zi. (53.37) may be used to obtain
As we shall soon see, generating functions can be used to solve recurrence
relations. First, let us look at the calculus of generating functions. Generating Function Operations Addition and Subtraction: If G 1(z) = Σcizi and G2(z) = Σdizi are the generat-
ing functions for f 1 and f 2, then the generating function for f 1 + f 2 is:
G 3(z) = Σ(ci+di)zi
4 (z ) = Σ (ci di)z i .
These two equalities follow directly from the definition of a generating function. Multiplication: If G 1(z) = Σcizi is the generating function for f, then G2(z) =
aG 1(z) = Σ(aci)zi is the generating function for a*f (a is a constant).
Since z kG 1(z) = Σcizk+i, it is the generating function for a function g such
that g(j) = 0, 0≤j<k and g(j) = f(j - k), j≥k. So, multiplying a generating functionby z k corresponds to shifting the function it generates by k. Example 53.14 In Example 53.13, we showed that = Σ(i +1)zi. Multi-
= Σ(i +1)zi+1 = Σizi. So,
the closed form for the generating function for f(i) = i, i≥0. 30 Chapter 53 Recurrence Equations
The product G 1(z)*G 2(z) of the two generating functions G 1(z) = Σcizi
and G 2(z) = Σdizi is a third generating function G3(z) = Σeizi. One may ver-
ei= Σi cjdi−j, i ≥ 0
Note that * is commutative (i.e., G 1(z) * G 2(z) = G 2(z) * G 1(z)).
An examination of (53.39) indicates that the product of generating func-
tions might be useful in computing sums. In particular, if G 2(z) = Σzi = 1−z
(Example 53.11) (i.e., di = 1, i≥0), then (53.39) becomes
Example 53.15 Let us try to find the closed form for the sum s(n) = Σn i. From
is the closed form for the generating func-
tion for f(i) = i, i≥0. Also, from Example 53.12, we know that
is the closed form for ( Σizi)(Σzi). Let
be Σeizi. From (53.40), it follows that
en= Σn i = s(n), n≥0. Let us proceed to determine en. Using the binomial
The coefficient of z n −1 in the expansion of (1-z)−3 is therefore:
= (n−1)(n−2).(1)
Section 53.5 Generating Functions 31
So, the coefficient en of z n in the power series form of
Differentiation: Differentiating (53.36) with respect to z gives:
___ G (z) = Σicizi−1
G (z) = Σ(ici)ziExample 53.16 In Example 53.13, the binomial theorem was used to obtain the closed form for Σ(i +1)zi. This closed form can also be obtained using
differentiation. From Example 53.12, we know that
Integration: Integrating (53.36), we get
∫G(u)du= Σcj−1zj/jExample 53.17 The closed form of the generating function for f (n) = 1/n, n≥1 can be obtained by integrating the generating function for f (n) = 1. From Exam- ple 53.12, we obtain: 32 Chapter 53 Recurrence Equations
∫_ 1___du= −ln(1−z)
So, the generating function for f (n) = 1/n, n≥1 and f(0) = 0, is -ln(1-z).
The five operations: addition, subtraction, multiplication, differentiation,
and integration prove useful in obtaining generating functions for f:N → R.
Figure 53.2 lists some of the more important generating functions in both
Solving Recurrence Equations
The generating function method of solving recurrences is best illustrated by anexample. Consider the recurrence:
The steps to follow in solving any recurrence using the generating functionmethod are:
Let G(z) = Σaizi be the generating function for F(). So, ai=F (i), i≥0.
Replace all occurrences of F() in the given recurrence by the correspondingai. Doing this on the example recurrence yields:
an= 2an −1 + 7, n≥1
Section 53.5 Generating Functions 33 i =0m = n if n≥0m = ∞ otherwise
Figure 53.2 Some power series.
Multiply both sides of the resulting equation by z n and sum up both sidesfor all n for which the equation is valid. For the example, we obtain:
Σanzn= 2Σan−1zn+ Σ7zn
Replace all infinite sums involving the ais by equivalent expressionsinvolving only G(z), z, and a finite number of the ais. For a degree krecurrence only a 0, a 1, ., ak −1 will remain. The example yields:
G (z) − a 0 = 2zG (z) + Σ 7zn
Substitute the known values of a 0, a 1, .,ak −1 (recall that F(i) = ai, 0≤i<k.
G(z) = 2zG (z) + Σ 7zn34 Chapter 53 Recurrence Equations
Solve the resulting equation for G(z). The example equation is easilysolved for G(z) by collecting the G(z) terms on the left and then dividingby the coefficient of G(z). We get:
G (z) = Σ 7zn ∗ 1−2z
Determine the coefficient of z n in the power series expansion of the expres-sion obtained for G(z) in step 6. This coefficient is an = F(n). For ourexample, we get:
The coefficient of z n in the above series product is:
Σn7*2n−i= 7(2n−1)
The next several examples illustrate the technique further. Example 53.18 Let us reconsider the recurrence for the Fibonacci numbers:
Let G(z) = Σcizi be the generating function for F. From the definition of a gen-
erating function, it follows that F(j) = cj, j≥0. So, F(n) = cn, F(n-1) = cn −1, and
F(n-2) = cn −2. From the recurrence relation for F, we see that:
cn=cn −1 +cn−2, n≥2
Multiplying both sides by z n and summing from n=2 to ∞, we get:
Σcnzn@=@Σcn−1zn+ Σcn−2znSection 53.5 Generating Functions 35
Observe that the sum cannot be performed from n = 0 to ∞ as the recurrence F(n)= F(n-1) + F(n-2) is valid only for n≥2. (53.43) may be rewritten as:
G(z)-c 1z-c 0 = z Σ cn−1zn−1 + z2 Σ cn−2zn−2
= z Σcizi+z2 Σcizi
= zG (z)−c 0z+z 2G (z)
Collecting terms and substituting c 0 = F(0) = 0 and c 1 = F(1) = 1, we get:
From Figure 53.2, we see that the power series expansion of (1-az)−1 is Σ(az)i. Example 53.19 Consider the recurrence: at (n −1)+bn n ≥1
Let G(Z) = Σcizi be the generating function for t(n). So, t (n) = cn, n≥0. From
36 Chapter 53 Recurrence Equations cn=acn −1 +bn, n≥1
Multiplying both sides by z n and summing from n=1 to ∞ yields:
Σcnzn= Σ acn−1zn + Σbnzn
G(z)-c 0 = az Σ cn−1zn−1 + Σ bnzn
Substituting c 0 = 0 and collecting terms, we get:
Using the formula for the product of two generating functions, we obtain:
cn = b Σn ian−i
Hence, t (n) = ba n ΣnExample 53.20 In the previous example, we determined that cn = ba n Σn
closed form for cn can be obtained from a closed form for dn= Σn
let us find the generating function for f(i) = i/a i. We know that (1-z)−1 = Σzi.
So, (1-z/a)−1 = Σ(z /a)i. Differentiating with respect to z, we obtain:
Section 53.5 Generating Functions 37
(z /a)i= Σ zi−1
The generating function for Σn i /ai can now be obtained by multiplying by 1/(1-
a (1−z /a)2(1−z)
We now need to find the form of the coefficient of z n in the expansion of
a (1−z /a)2(1−z)
Σ(z /a)i Σ(z /a)i Σzia (1−z /a)2(1−z)
a (1/a − 1) i =0 a n38 Chapter 53 Recurrence Equations
When a = 1, dn= Σn i = n(n+1)/2. Observe that the recurrence for dn is:
dn=dn −1 +
Since the general form of the particular solution is not known when g(n) = n/a n,it would be difficult to obtain the solution for dn using the characteristic rootsmethod. Example 53.21 An alternate approach to obtain the power series form of G(z) = ( Σ bnzn)/(1−az) (see Example 53.19) is:
G(z) = ( Σ bnzn)/(1−az)
= (b Σ nzn)/(1−az). Section 53.5 Generating Functions 39
= A Σizi+BΣ(i +1)zi+CΣaizi
The coefficient of z n is therefore:
t(n) = An+B (n +1) +Ca n
Σi(i+1)zi (Example 53.15)
So, f (n) = bn(n+1)/2, n≥0, a=1. Example 53.22 Consider the recurrence:
Let G(z) = Σcizi be the generating function for f. So, f (n) = cn, f(n-1) = cn−1
cn= 5cn −1 − 6cn −2 + 2n , n≥2
40 Chapter 53 Recurrence Equations cnz n= 5cn −1z n − 6cn −2z n+ 2nz n, n≥2
Σcnzn = 5z Σcn−1zn−1 − 6z2 Σcn−2zn−2 + Σ 2nzn
G(z)-c 1z−c 0 = 5z (G (z)−c 0) − 6z 2G (z) + Σ 2nzn
Substituting c 1 = c 0 = 0, we get:
= Σ 2jz j[3Σ3izi − 2Σ2izi]
The coefficient cn of z n is now seen to be:
cn = Σn 6j3n−j − Σn 4j2n−j
= 6* 3n Σn (j /3j) − 4* 2n Σn j /2jSection 53.5 Generating Functions 41 cn = −3n−4.5+4.5* 3n−2* 3n+4n+8−8* 2n+2* 2n=n+3.5+2.5* 3n−6* 2n
So, f (n) = n+3.5+2.5* 3n−6* 2n, n≥0. REFERENCES AND SELECTED READINGS
Figure 53.1 is due to J. Bentley, D. Haken, and J. Saxe. They presented it in theirsolution of recurrence (53.15). Their work appears in the report A generalmethod for solving divide-and-conquer recurrences, by J. Bentley, D. Haken,and J. Saxe, SIGACT News, 12(3), 1980, pp. 36-44.
A proof of Theorem 53.3 may be found in Introductory combinatorics, by
R. Brualdi, Elsevier North-Holland Inc., New York, 1977.
SOCIAL PHOBIA Pavo Filakovi 1, Veljko or evi 2, Elvira Koi 3 and Lana Mu ini 4. 1Psychiatric Clinic, University Hospital Osijek; 3Psychiatric Department, General Hospital Virovitica; ABSTRACT Social anxiety disorder (Social phobia) is an irrational fear of being observed and judged by other people in various social settings. It is often a chronic, disabling condition that is character
PATIENT SUMMARY OF INFORMATION ABOUT This summary contains important information about VIAGRA®. It is not meant to take the place of your doctor’s instructions. Read this information carefully before you start taking VIAGRA. Ask your doctor or pharmacist if you do not understand any of this information or if you want to know more about VIAGRA. This medicine can help many men when i