22: Even More Recursion

Submit this homework using Gradescope. You can type up your answers, or write legibly and scan them. Do not attempt to submit a paper copy in class, as it will not be accepted.


Suppose you have a tree composed of Nodes:

public class Node<E> {
    public E data;
    public Node<E> left;
    public Node<E> middle;
    public Node<E> right;
}

where each node has up to three children.

(1 point) Write a recursive Integer max(Node<Integer> node) method that returns the largest Integer stored by a Node in the tree rooted at node. If node is null, this should return null. You may assume that all non-null Nodes have non-null data fields.

Obviously this is not a binary search tree – you have examine everyone node in the tree!