

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A university assignment on binary trees, including questions on node counting, local minimum finding, and tree printing in java. The assignment includes instructions for each question, a hint for the first question, and an example of a binary tree for the tree printing question.
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Assignment 8 Due: 20th^ Oct 2008
Hint: If we remove two leaf nodes that are under the same parent, every non-leaf node of the new tree will still have non-empty left and right sub- trees. How does this change the number of leaf (and non-leaf) nodes?
(a) Prove that any such tree has at least one local minimum. (b) Write an efficient (fewest probes) algorithm for finding one local minimum of T (maybe there are many, you only need to find one). Calculate the time complexity for your algorithm.
treeprint(node t, int n)
that will pretty-print a binary tree in indented format, using a preorder traversal. The argument n is the current depth in the tree, whose value at the beginning of the recursion is assumed to be zero. For example:
a (3) ... b (1) ... ... c(0) ... d (2) ... ... e (0) ... ... f (0) ... g (0)
In this tree, a has 3 children (b,d,g), b has one child (c), and d has 2 children (e and f).