(c) For the same graph
G
assume that each edge has a weight obtained by adding the numbers
of the two vertices at its ends. For example,
12
has weight 3 and
35
has weight 8. Give a
minimal spanning tree for
G
.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document5. (15 pts) Consider sequences of queue operations, each operation being an enqueue or a dequeue. We
assume that the sequences are such that the empty queue exception is never thrown. Let
M
be a
function that, given such a sequence
s
of queue operations, computes the minimum initial size of
the array in which we implement the queue, such that the whole sequence
s
of operations can be
performed without having to increase the size of the array. Give the pseudocode for
M
in two cases:
(a) The simple array implementation which suﬀers from the problem of drift.
(b) The circular array implementation.
6. (20 points)
static int foo(char[] a) {
for (int j = 2; j < a.length; j = j*j )
a[j] = ’z’;
return (a.length * a.length * a.length);
}
static void bar(char[] b) {
for (int i = 1; i < foo(b); i=2*i)
b[i]=’z’;
}
Analyze the worstcase running time of
bar(b)
as a function of
n
=
b.length
and give a BigOh
bound.
7. (15 pts)
(a) Draw a binary search tree with integer keys such that when we traverse the tree in postorder
we obtain 3
,
5
,
6
,
4
,
8
,
9
,
7.
(b) Draw an AVL binary search tree with integer keys such that when we traverse the tree in
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '09
 TANNEN
 Algorithms, Data Structures, pts

Click to edit the document details