finmock1

# B draw an avl binary search tree with integer keys

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

(b) Draw an AVL binary search tree with integer keys such that when we traverse the tree in postorder we obtain 3 , 5 , 6 , 4 , 8 , 9 , 7. 8. (20 pts) Consider the following code fragment involving recursive calls: public static long fob (int n) { if (n <= 17) return n; else return fob(n-1) + gob(n-1) + 11; } public static long gob (int n) { if (n <= 13) return n; else return fob(n-1) + 7; } 2

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
(a) Explain why a call to fob(n) leads to a number of recursive calls that is exponential in n . (b) Give a Java method public static long fob (int n) that computes the same value as fob(n) but does it in time O ( n ). (Points will not be deducted for syntactic errors so don’t worry about them.) 9. (15 pts) A tree can be also regarded as a digraph, with the direction of the edges being always toward the leaves and away from the root (“downwards” in the usual tree diagrams we use). Prove by induction on the bottom-up view of trees that for any binary tree T the traversal in preorder produces a list of nodes that is also a topological ordering of T regarded as a digraph. 10. (15 pts) A min-heap contains the keys 1 , 2 ,..., 63. Explain why the key 50 cannot appear at depth 2. 11. (15 pts) Describe a data structure that implements on a collection of comparable elements the fol- lowing operations, add, removeMin, removeMax, ﬁndMin, ﬁndMax, each in O (log n ) 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page2 / 3

b Draw an AVL binary search tree with integer keys such...

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

View Full Document
Ask a homework question - tutors are online