{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

A explain why a call to fobn leads to a number of

Info iconThis preview shows page 3. Sign up to view the full content.

View Full Document Right Arrow Icon
(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, findMin, findMax, each in O (log n ) 3
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}