This preview shows pages 1–2. Sign up to view the full content.
Algorithms
Appendix II: Solving Recurrences
[
Fa’10
]
Change is certain. Peace is followed by disturbances; departure of evil men by their
return. Such recurrences should not constitute occasions for sadness but realities for
awareness, so that one may be happy in the interim.
—
I Ching [The Book of Changes]
(c. 1100 BC)
“...O Zarathustra, who you are and must become” behold you are the teacher of the
eternal recurrence – that is your destiny! That you as the ﬁrst must teach this doctrine –
how could this great destiny not be your greatest danger and sickness too?
— Friedrich Nietzsche,
Also sprach Zarathustra
(1885)
[translated by Walter Kaufmann]
Wil Wheaton:
Embrace the dark side!
Sheldon:
That’s not even from your franchise!
— “The Wheaton Recurrence”,
Bing Bang Theory
, April 12, 2010
Solving Recurrences
1 Introduction
A
recurrence
is a recursive description of a function, or in other words, a description of a function in
terms of itself. Like all recursive structures, a recurrence consists of one or more
base cases
and one or
more
recursive cases
. Each of these cases is an equation or inequality, with some function value
f
(
n
)
on the left side. The base cases give explicit values for a (typically ﬁnite, typically small) subset of the
possible values of
n
. The recursive cases relate the function value
f
(
n
)
to function value
f
(
k
)
for one or
more integers
k
<
n
; typically, each recursive case applies to an inﬁnite number of possible values of
n
.
For example, the following recurrence (written in two different but standard ways) describes the
identity function
f
(
n
) =
n
:
f
(
n
) =
(
0
if
n
=
0
f
(
n

1
)+
1
otherwise
f
(
0
) =
0
f
(
n
) =
f
(
n

1
1 for all
n
>
0
In both presentations, the ﬁrst line is the only base case, and the second line is the only recursive case.
The same function can satisfy
many
different recurrences; for example, both of the following recurrences
also describe the identity function:
f
(
n
) =
0
if
n
=
0
1
if
n
=
1
f
(
b
n
/
2
c
f
(
d
n
/
2
e
)
otherwise
f
(
n
) =
0
if
n
=
0
2
·
f
(
n
/
2
)
if
n
is even and
n
>
0
f
(
n

1
1
if
n
is odd
We say that a particular function
satisﬁes
a recurrence, or is the
solution
to a recurrence, if each
of the statements in the recurrence is true. Most recurrences—at least, those that we will encounter
in this class—have a solution; moreover, if every case of the recurrence is an equation, that solution is
unique. Speciﬁcally, if we transform the recursive formula into a recursive
algorithm
, the solution to the
recurrence is the function computed by that algorithm!
Recurrences arise naturally in the analysis of algorithms, especially recursive algorithms. In many
cases, we can express the running time of an algorithm as a recurrence, where the recursive cases of the
recurrence correspond exactly to the recursive cases of the algorithm. Recurrences are also useful tools
for solving counting problems—How many objects of a particular kind exist?
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
 Fall '08
 Chekuri,C
 Algorithms

Click to edit the document details