This preview shows pages 1–3. Sign up to view the full content.
Introduction to Algorithms
May 10, 2005
Massachusetts Institute of Technology
6.046J/18.410J
Professors Charles E. Leiserson and Ronald L. Rivest
Practice Final Exam—From Fall 2004
Practice Final Exam—From Fall 2004
Problem 1. Recurrences
(4 parts) [8 points]
For each of the recurrences below, do the following:
•
Give the solution using
Θ
notation. You need not provide a proof or other justification.
•
Name a recursive algorithm we’ve seen during the term whose running time is described by
that recurrence.
(a)
T
(
n
) =
T
(
n/
2) + Θ(1)
Solution:
Θ(log
n
)
. Binary search.
(b)
T
(
n
) = 2
T
(
n/
2) + Θ(
n
)
Solution:
Θ(
n
log
n
)
. M
ERGE
S
ORT
.
(c)
T
(
n
) =
T
(
n/
5) +
T
(7
n/
10) + Θ(
n
)
Solution:
Θ(
n
)
. S
ELECT
(d)
T
(
n
) = 7
T
(
n/
2) + Θ(
n
2
)
Solution:
Θ(
n
lg 7
)
. Strassen’s matrixmultiplication algorithm.
Problem 2. Design Techniques and Data Structures
(5 parts) [10 points]
For each of the following design techniques and data structures, name an algorithm covered this
term that uses it.
(a)
Divide and conquer:
Solution:
M
ERGE
S
ORT
uses divide and conquer. It divides the problem into two
problems of half the size (the left and right halves of the array, conquers the subprob
lems by running M
ERGE
S
ORT
recursively, and combines the results by merging the
subarrays together.
(b)
Dynamic programming:
Solution:
The typesetting problem used dynamic programming.
(c)
Greedy:
Solution:
Prim’s algorithm for minimum spanning tree is a greedy algorithm.
(d)
Binary search tree:
Solution:
The dynamic maximumprefix problem from problem set 4 used an aug
mented redblack tree.
(e)
FIFO queue:
Solution:
Breadthfirst search uses a FIFO queue.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document 6.046J/18.410J Practice Final Exam—From Fall 2004
Name
2
Problem 3. True or False, and Justify
(12 parts) [84 points]
Circle
T
or
F
for each of the following statements to indicate whether the statement is true or
false, respectively. If the statement is correct, briefly state why. If the statement is wrong, explain
why. The more content you provide in your justification, the higher your grade, but be brief. Your
justification is worth more points than your trueorfalse designation.
(a) T F
If
f
(
n
)
is asymptotically positive, then
f
(
n
) +
o
(
f
(
n
)) = Θ(
f
(
n
))
.
Solution:
True.
Clearly,
f
(
n
) +
o
(
f
(
n
))
is
Ω(
f
(
n
))
, so let us prove that
f
(
n
) +
o
(
f
(
n
)) =
O
(
f
(
n
))
. Let
g
(
n
)
∈
o
(
f
(
n
))
. Then for any
c >
0
, there exists
n
0
such that
g
(
n
)
≤
c
(
f
(
n
))
for all
n
≥
n
0
. Hence,
f
(
n
) +
g
(
n
)
≤
(
c
+ 1)
f
(
n
)
for all
n
≥
n
0
, which means that
f
(
n
) +
g
(
n
) =
O
(
f
(
n
))
.
(b) T F
An adversary can provide an input to randomized quicksort that will elicit
1
its
Θ(
n
2
)
worstcase running time.
Solution:
This is the end of the preview. Sign up
to
access the rest of the document.
This note was uploaded on 01/20/2012 for the course CS 6.006 taught by Professor Erikdemaine during the Spring '08 term at MIT.
 Spring '08
 ErikDemaine
 Algorithms

Click to edit the document details