finmock1

C for the same graph g assume that each edge has a

This preview shows pages 1–3. Sign up to view the full content.

(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, 1-2 has weight 3 and 3-5 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 Document
5. (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 worst-case running time of bar(b) as a function of n = b.length and give a Big-Oh 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.

{[ snackBarMessage ]}

Page1 / 3

c For the same graph G assume that each edge has a weight...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online