CS 61A

Structure and Interpretation of Computer Programs, Spring 2015

Instructor: John DeNero




Question | Find Max

Define find_max, which takes a non-rooted tree t, and returns the maximum entry in t. You may assume is_leaf(tree) is defined for you.

def find_max(t):
    """
    >>> t1 = [1, [2, 3], [3, [4, 3]]]
    >>> find_max(t1)
    4
    """
    ## YOUR CODE HERE ##
def find_max(tree):
    if is_leaf(tree):
        return tree
    new_tree = [find_max(t) for t in tree]
    return max(new_tree)