Complete the code to visit the left subtree first in postorder traversal.
def postorder(node): if node is None: return postorder(node.[1]) print(node.val, end=' ')
In postorder traversal, we visit the left subtree first, so we call postorder(node.left).
Complete the code to visit the right subtree second in postorder traversal.
def postorder(node): if node is None: return postorder(node.left) postorder(node.[1]) print(node.val, end=' ')
In postorder traversal, after visiting the left subtree, we visit the right subtree by calling postorder(node.right).
Fix the error in printing the node value in postorder traversal.
def postorder(node): if node is None: return postorder(node.left) postorder(node.right) print(node.[1], end=' ')
The node's value is stored in val, so we print node.val.
Fill both blanks to create a dictionary comprehension that maps node values to their depths during postorder traversal.
depth_map = {node.val: [1] for node in nodes if node.[2] is not None}We map each node's value to its depth plus one, and filter nodes that have a right child (node.right is not None).
Fill all three blanks to create a dictionary comprehension that maps uppercase node values to their depths if depth is greater than zero.
result = [1]: [2] for node in nodes if [3] > 0
The comprehension maps uppercase node values to their depths, filtering nodes with depth greater than zero.
