A file-browser program needs a function that mirrors a binary tree: it exchanges left and right children at every node while preserving each stored label. None represents an empty tree, and Node(label, left, right) constructs a node with the given children.
The following Python function exchanges the root's children but does not transform the subtrees. Repair its final return statement using structural recursion, applying the function to the child structures before constructing the result.
def mirror(t): if t is None: return None return Node(t.label, t.right, t.left)
The diagram gives an example input with branching below the root.
In the corrected return statement, the left-child argument is and the right-child argument is . Write the expressions using the exact function and attribute names shown, without spaces.
Unlock full course notes by signing up
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.
Empty structure versus a zero value
A program totals values in a finite binary tree with no cycles or shared nodes. Each nonempty node has value, left and right fields, and an empty child is None. Select every correct statement about the function.
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.
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.