Introduction to Algorithms
October 13, 2010
Massachusetts Institute of Technology
6.006 Fall 2010
Professors Konstantinos Daskalakis and Patrick Jaillet
Quiz 1 Solutions
Quiz 1 Solutions
Problem 1.
We hope you mastered this question. Your name is that thing you include at the top
of your problem set when you submit. Found yourself tonguetied? This question is bound to show
up on future quizes, so feel free to put it on your crib sheet for free points. Not that two points is
enough to really dominate the quiz, but it’s a start.
Problem 2.
Asymptotics & Recurrences
[20 points]
(3 parts)
(a)
[10 points] Rank the following functions by
increasing
order of growth. That is, find
any arrangement
g
1
, g
2
, g
3
, g
4
, g
5
, g
6
, g
7
, g
8
of the functions satisfying
g
1
=
O
(
g
2
)
,
g
2
=
O
(
g
3
)
,
g
3
=
O
(
g
4
)
,
g
4
=
O
(
g
5
)
,
g
5
=
O
(
g
6
)
,
g
6
=
O
(
g
7
)
,
g
7
=
O
(
g
8
)
.
f
1
(
n
) =
n
log
2
n
f
2
(
n
) =
n
+
√
n
log
4
n
f
3
(
n
) =
n
4
f
4
(
n
) =
n
n/
3
f
5
(
n
) =
n
n

2
f
6
(
n
) = 2
log
2
n
f
7
(
n
) =
n
√
log
n
f
8
(
n
) =
n
3
n
2
Solution:
f
2
, f
1
, f
5
, f
3
, f
8
, f
7
, f
6
, f
4
(b)
[5 points] Find an asymptotic solution of the following functional recurrence. Express
your answer using
Θ
notation, and give a brief justification.
T
(
n
) = 16
·
T
(
n/
4) +
n
2
log
3
n
Solution:
Using Master Theorem, we compare
n
2
log
3
n
with
n
log
4
16
=
n
2
. This is
case 2 of the generalized version of the theorem as treated in class, so we increment
the
log
k
n
for
Θ(
n
2
log
4
n
)
.
(c)
[5 points] Find an asymptotic solution of the following recurrence.
Express your
answer using
Θ
notation, and give a brief justification. (Note that
n
1
log
n
= 1
.)
T
(
n
) =
T
(
√
n
) + 1
Solution:
T
(
n
) = Θ(log log
n
)
.
To see this, note that
q
. . .
√
n

{z
}
i
times
=
n
1
/
2
i
. So, once
i
becomes
log log
n
we will have
n
1
/
2
i
=
n
1
/
log
n
= 1
. Thus the recursion stops after
log log
n
levels and each level
contributes
1
, hence
T
(
n
) = Θ(log log
n
)
.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
6.006 Quiz 1 Solutions
Name
2
Problem 3.
True/False
[18 points]
(9 parts)
Circle (T)rue or (F)alse. You don’t need to justify your choice.
(a)
T F
[2 points] Inserting into an AVL tree can take
o
(log
n
)
time.
Solution:
False.
To answer this question, we need to know the length of the
shortest possible path from the root to a leaf node in an AVL tree with
n
elements.
In the best possible case, for each node we pass, the heights of its two children
differ by 1, and we move to the child with the lower height. The child’s height is
then 2 less than the current node’s height. So in the best case, each time we move
to a new node, the height decreases by 2. The number of times we do this to get
to height 0 is then the height of the root divided by 2. The height of the root is
Θ(log
n
)
, so it takes
1
/
2
·
Θ(log
n
) = Θ(log
n
)
time to insert into an AVL tree,
in the best case. Therefore it cannot take
o
(log
n
)
time.
(b)
T F
[2 points] If you know the numbers stored in a BST and you know the structure
of the tree, you can determine the value stored in each node.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '08
 ErikDemaine
 Algorithms, Big O notation, hash function, FN

Click to edit the document details