A. It visits right subtree before left subtree, reversing order
B. It causes infinite recursion
C. It visits the root before children
D. It does not check for null root
Solution
Step 1: Analyze traversal order in code
The code calls postorder on right subtree first, then left subtree, then visits root.
Step 2: Compare with correct postorder order
Correct postorder is left, right, root. This code reverses left and right subtree order.
Final Answer:
It visits right subtree before left subtree, reversing order -> Option A
Quick Check:
Left before right needed, code does right before left [OK]
Hint: Left subtree must be visited before right in postorder [OK]
Common Mistakes:
Swapping left and right subtree calls
Ignoring null check (though present here)
Visiting root before children
5. You want to collect all node values of a binary tree in postorder traversal into a list. Which of the following Java code snippets correctly implements this?