Therefore
T
(
n
) is
O
(
n
log
n
).
Grading guidelines:
(a) 15 points total; 5 points for correct and explicit analysis of for loops; 5 points
for correct and explicit analysis of recursive calls; 3 points for correctly stating that the complexity
of array creation is
O
(1); 2 points for correct recurrence relation.
(b) 10 points total; 5 points for correctly solving the recurrence; but you lose 2 if no base case stated;
ﬁnally 5 points for correct ﬁnal answer
O
(
nlogn
).
8. (40 pts) For each statement below, decide whether it is true or false. In each case attach a
very brief
explanation of your answer.
(a) In a binary minheap both the smallest and the largest key are on leaves, true or false?
Answer:
FALSE. The largest key must be on a leaf but the smallest key is on the root.
(b) In a binary search tree both the smallest and the largest key are on leaves, true or false?
Answer:
FALSE. Neither has to be on a leaf. The smallest key must be a on a node without
left child but the node may have a right child. The largest key must be a on a node without
right child but the node may have a left child.
(c) The worstcase complexity of inserting
n
keys in an (empty to begin with) hashtable with open
addressing and linear probing is
O
(
n
2
), true or false?
Answer:
TRUE. For example if the keys are consecutive integers.
(d) There exists a function
f
(
n
) such that
f
(
n
) is Ω(
n
2
) and is
O
(
n
3
) but is neither Θ(
n
2
) nor
Θ(
n
3
), true or false?
Answer:
TRUE. For example,
f
(
n
) =
n
2
√
n
or
f
(
n
) =
n
2
log
n
.
(e) There exist undirected graphs on which BFS traversal takes time Θ(

V

), true or false?
Answer:
TRUE. For example, if the graph has no edges.
(f) We can compute the strongly connected components of a DAG in time
O
(

V

), true or false?
Answer:
TRUE. In a DAG the strongly connected components consist of single nodes. To
compute them just scan the array of nodes.
6
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document(g) Let
G
be a digraph with
n
nodes and
s
one of its nodes. The discovery edges found by DFS
starting from
s
always form a tree with
n

1 edges, true or false?
Answer:
FALSE. They form a tree but the nodes in this tree are only those nodes reachable
by a path from
s
and there may be strictly less than
n
such nodes, therefore the tree may have
strictly less than
n

1 edges.
(h) In a 4way trie we store 3 distinct keys, each of them a 2character string. The resulting trie
can have as many as 22 null links, true or false?
Answer:
TRUE. The trie is largest of all 3 keys have a diﬀerent ﬁrst character. Then there 1
null link from the root, 9 null links from the 3 nodes at depth 1, and 12 null links from the 3
nodes at depth 2. 1 + 9 + 12 = 22.
Grading guidelines:
As usual: 2 points for correct true or false statement; 3 points for for correct
explanation.
9. (20pts) Consider the following undirected weighted graph (ﬁve nodes labeled
A,B,C,D,E,F
and the
edge weights are either 1 or 3 as shown). We use Dijkstra’s algorithm to compute the lengths of the
shortest paths from
A
to the other nodes.
!
#
$
%
'
(
(
(
(
(
(
)
)
)
)
(a) Dijkstra’s algorithm begins by relaxing the edges
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '09
 TANNEN
 Algorithms, Graph Theory, Data Structures, Big O notation, Analysis of algorithms, hash function, theMin

Click to edit the document details