Lecture Notes
CMSC 251
We have this messy summation to solve though. First observe that the value
n
remains constant
throughout the sum, and so we can pull it out front. Also note that we can write
3
i
/
4
i
and
(3
/
4)
i
.
T
(
n
)=
n
log
4
3
+
n
(log
4
n
)

1
X
i
=0
±
3
4
²
i
.
Note that this is a geometric series. We may apply the formula for the geometric series, which gave in
an earlier lecture. For
x
6
=1
:
m
X
i
=0
x
i
=
x
m
+1

1
x

1
.
In this case
x
=3
/
4
and
m
= log
4
n

1
. We get
T
(
n
n
log
4
3
+
n
(3
/
4)
log
4
n

1
(3
/
4)

1
.
Applying our favorite log identity once more to the expression in the numerator (with
a
/
4
and
b
=4
)weget
(3
/
4)
log
4
n
=
n
log
4
(3
/
4)
=
n
(log
4
3

log
4
4)
=
n
(log
4
3

1)
=
n
log
4
3
n
.
If we plug this back in, we have
T
(
n
n
log
4
3
+
n
n
log
4
3
n

1
(3
/
4)

1
=
n
log
4
3
+
n
log
4
3

n

1
/
4
=
n
log
4
3

4(
n
log
4
3

n
)
=
n
log
4
3
+4(
n

n
log
4
3
)
n

3
n
log
4
3
.
So the ﬁnal result (at last!) is
T
(
n
)=4
n

3
n
log
4
3
≈
4
n

3
n
0
.
79
∈
Θ(
n
)
.
It is interesting to note the unusual exponent of
log
4
3
≈
0
.
79
. We have seen that two nested loops typi
cally leads to
Θ(
n
2
)
time, and three nested loops typically leads to
Θ(
n
3
)
time, so it seems remarkable
that we could generate a strange exponent like
0
.
79
as part of a running time. However, as we shall
see, this is often the case in divideandconquer recurrences.
Lecture 8: More on Recurrences
(Thursday, Feb 19, 1998)
Read:
Chapt. 4 on recurrences, skip Section 4.4.
Recap:
Last time we discussed recurrences, that is, functions that are deﬁned recursively. We discussed
their importance in analyzing divideandconquer algorithms. We also discussed two methods for solv
ing recurrences, namely guessandverify (by induction), and iteration. These are both very powerful
methods, but they are quite “mechanical”, and it is difﬁcult to get a quick and intuitive sense of what
is going on in the recurrence. Today we will discuss two more techniques for solving recurrences. The
ﬁrst provides a way of visualizing recurrences and the second, called the Master Theorem, is a method
of solving many recurrences that arise in divideandconquer applications.
27
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentLecture Notes
CMSC 251
Visualizing Recurrences Using the Recursion Tree:
Iteration is a very powerful technique for solving re
currences. But, it is easy to get lost in all the symbolic manipulations and lose sight of what is going
on. Here is a nice way to visualize what is going on in iteration. We can describe any recurrence in
terms of a tree, where each expansion of the recurrence takes us one level deeper in the tree.
Recall that the recurrence for MergeSort (which we simpliﬁed by assuming that
n
is a power of 2, and
hence could drop the ﬂoors and ceilings)
T
(
n
)=
±
1
if
n
=1
,
2
T
(
n/
2) +
n
otherwise.
Suppose that we draw the recursion tree for MergeSort, but each time we merge two lists, we label that
node of the tree with the time it takes to perform the associated (nonrecursive) merge. Recall that to
merge two lists of size
m/
2
to a list of size
m
takes
Θ(
m
)
time, which we will just write as
m
. Below
is an illustration of the resulting recursion tree.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '11
 Staff
 Recursion, Big O notation, Recurrence relation, Asymptotic analysis, Master Theorem, recursion tree

Click to edit the document details