Total visits and deepest active recursion

A diagnostics routine visits the linked records shown in the binary tree. Missing child links are None. Python evaluates the left recursive call before the right recursive call.


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

visit(A)


Find the total number of visit invocations during this execution and the maximum number of simultaneously active visit invocations. An invocation is active from entry until it returns. Include the initial invocation and invocations whose argument is None, and exclude the caller outside visit. Give both answers in calls, as exact whole numbers.


A binary tree has root A with children B and C, a chain from B through D to E, and a right child F below C.


Your answers

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: