1 C 3 C 9 C _ _ _ C 3n1 D
nX1
iD0
3i D
1 3n
13
D
3n 1
2
(9.10)
If the terms in a geometric sum grow smaller, as in Equation 9.6, then the sum is
said to be geometrically decreasing. If the terms in a
which is, indeed, the case.
Equation 9.22 can be verified by induction. The base case when n D 1 is true
since we know that S1 D 1=2. The inductive step follows from Equation 9.21.
So we now know the
Definition 7.8.1. A chain is a sequence a1 _ a2 _ _ _ _ _ at , where ai aj for all
i j , such that each item is comparable to the next in the chain, and it is smaller
with respect to _. The length of
3
4
5
6
7
Figure 10.2 The 7-step solution to the Towers of Hanoi problem when there are
n D 3 disks.
1
2
3
Figure 10.3 A recursive solution to the Towers of Hanoi problem.
mcs-ftl 2010/9/8 0:40 page 2
the plug-and-chug procedure.
10.3 Linear Recurrences
So far weve solved recurrences with two techniques: guess-and-verify and plugandchug. These methods require spotting a pattern in a sequence of num
iD0
xi D
1
1x
:
Proof.
1X
iD0
xi WWD
n!1
nX1
iD0
xi
lim
D lim
n!1
1 xn
1x
(by Equation 9.3)
D
1
1x
:
The final line follows from that fact that limn!1 xn D 0 when jxj < 1. _
In our annuity problem, x
25
12
:
There is good news and bad news about Harmonic numbers. The bad news is that
there is no closed-form expression known for the Harmonic numbers. The good
news is that we can use Theorem 9.3.1 t
or product symbols or otherwise need those handy (but sometimes troublesome)
dots. . . . Expressions in closed form are usually easier to evaluate (it doesnt get
much simpler than 2N 1, for example) a
: (9.14)
It turns out that there is a way to derive these expressions, but before we explain
it, we thought it would be fun4 to show you how Gauss proved Equation 9.13 when
he was a young boy.5
Gausss
D 3=4:
Both cases give the same spread, albeit by different approaches. For example, see
Figure 9.10.
That was easy enough. What about S3?
S3 D max
_
1
1
6
;
3
4
C
1
6
_
D max
_
5
6
;
11
12
_
D
11
12
chug. These methods are applicable to every recurrence, but their success requires
a flash of insightsometimes an unrealistically brilliant flash. So well also
introduce two big classes of recurrences
case, the spread is maximized by having the center of mass of the top n 1 blocks
be directly over the left edge of the bottom block.
mcs-ftl 2010/9/8 0:40 page 263 #269
9.4. Hanging Out Over the Edge
table
center of mass
of block
Figure 9.6 One block can overhang half a block length.
In general, the overhang of a stack of blocks is maximized by sliding the entire
stack rightward until its center o
Comparing the shaded regions in Figures 9.1 and 9.2, we see that S is at least
I plus the area of the leftmost rectangle. Hence,
S _ I C f .1/ (9.15)
This is the lower bound for S. We next derive the
x _0
T y, since _0
T is a topological sort of the partial order _0. And this
implies x _T y since _T contains _0
T.
Thus, .A;_T / is a topological sort of .A;_/. This shows that P.n/ implies
P.n C 1/
: (9.11)
The left-hand side of Equation 9.11 is simply
nX1
iD0
d
dx
.xi / D
nX1
iD0
ixi1:
The right-hand side of Equation 9.11 is
nxn1.1 x/ .1/.1 xn/
.1 x/2
D
nxn1 C nxn C 1 xn
.1 x/2
D
1 nxn1 C .n 1/
Corollary 7.9.2 implies a famous result8 about partially ordered sets:
Lemma 7.9.3 (Dilworth). For all t > 0, every partially ordered set with n elements
must have either a chain of size greater than
x
.1 x/2 :
As a consequence, suppose that there is an annuity that pays im dollars at the
end of each year i forever. For example, if m D $50,000, then the payouts are
$50,000 and then $100,000 and th
2n D O.n/, we can say O.n/ D 2n. But n D O.n/, so we conclude that n D
O.n/ D 2n, and therefore n D 2n. To avoid such nonsense, we will never write
O.f / D g.
Similarly, you will often see statements
n3=2 C
p
n
2
3
:
In other words, the sum is very close to 2
3n3=2.
Well be using Theorem 9.3.1 extensively going forward. At the end of this
chapter, we will also introduce some notation that expresse
T .n/ D .n2/:
Little Omega
There is also a symbol called little-omega, analogous to little-oh, to denote that one
function grows strictly faster than another function.
Definition 9.7.14. For functions
5
2
1
p
5
2
!n
D
1
p
5
1C
p
5
2
!nC1
1
p
5
1
p
5
2
!nC1
:
mcs-ftl 2010/9/8 0:40 page 298 #304
298 Chapter 10 Recurrences
It is easy to see why no one stumbled across this solution for almost six centu
Similarly, the third payment is worth m=.1 C p/2, and the n-th payment is worth
only m=.1 C p/n1. The total value, V , of the annuity is equal to the sum of the
1Such
trading ultimately led to the sub
Proof. .x2C100xC10/=x2 D 1C100=xC10=x2 and so its limit as x approaches
infinity is 1C0C0 D 1. So in fact, x2C100xC10 _ x2, and therefore x2C100xC
10 D O.x2/. Indeed, its conversely true that x2 D O.x
ln.f .i /:
We can then apply our summing tools to find a closed form (or approximate closed
form) for ln.P / and then exponentiate at the end to undo the logarithm.
For example, lets see how this work
mcs-ftl 2010/9/8 0:40 page 269 #275
9.5. Double Trouble 269
Definition 9.4.2. For functions f; g W R ! R, we say f is asymptotically equal to
g, in symbols,
f .x/ _ g.x/
if
lim
x!1
f .x/=g.x/ D 1:
Alt
Figure 9.3 The shaded area under the curve of f .x C1/ from 0 to n1 is I , the
same as the area under the curve of f .x/ from 1 to n. This curve is the same as the
curve in Figure 9.2 except that has
mcs-ftl 2010/9/8 0:40 page 293 #299
10.2. Merge Sort 293
Step 1: Plug and Chug Until a Pattern Appears
First, we expand the recurrence equation by alternately plugging and chugging until
a pattern app