Given the recursive nature of a binary tree, a good strategy for writing a Java method that operates on a binary tree is often first to write a recursive definition of the task. Given such a recursive definition, a Java implementation is often straightforward.
Write recursive definitions that perform the following tasks on arbitrary binary trees. Implement the definitions in Java. Must your methods be members of BinaryTree? For simplicity, assume that each data item in the tree is an integer object and that there are no duplicates.
a. Count the number of nodes in the tree. (Hint. If the tree is empty, the count is 0. If the tree is not empty, the count is 1 plus the number of nodes in the root’s left subtree plus the number of nodes in the root’s right subtree.)
b. Compute the height of a tree.
c. Find the maximum element.
d. Find the sum of the elements.
e. Find the average of the elements.
f. Find a specific item.
g. Determine whether one item is an ancestor of another (that is, whether one item is in the subtree rooted at the other item).
h. Determine the highest level that is full or, equivalently, has the maximum number of nodes for that level.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.