Building tree heights from child results

A navigation program stores records in the binary tree shown. Each record has left and right child links; every missing child is None. Complete the table with the exact whole-number result of calling height on each indicated subtree. Empty means None.


Python
def height(node):
    if node is None:
        return 0
    return 1 + max(height(node.left), height(node.right))


A binary tree has root P, children Q and R, and a right child S below Q.


Subtree rootHeight in nodes
Empty
S
Q
R
P

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Structural Recursion Questions: