A. It visits the right subtree before the left subtree, reversing the correct order
B. It does not check if root is NULL before recursion
C. It prints the root before visiting children
D. It causes infinite recursion
Solution
Step 1: Analyze the order of recursive calls
The code calls postorder on right subtree first, then left subtree, which reverses the expected left-right order.
Step 2: Check printing position
Printing root after children is correct, but subtree order is wrong.
Final Answer:
Visits right subtree before left, reversing order -> Option A
Quick Check:
Left before right needed, code does right before left [OK]
Hint: Left subtree call must come before right subtree call [OK]
Common Mistakes:
Swapping left and right subtree calls
Printing root too early
Missing null check (not in this code though)
5. You have a binary tree where each node stores an integer. You want to collect all node values in postorder traversal into an array. Which approach correctly achieves this?
hard
A. Use recursion: traverse left subtree, traverse right subtree, then append root value to array
B. Use recursion: append root value, then traverse left and right subtrees
C. Use a queue to enqueue root first, then left and right children
D. Traverse the tree level by level and append nodes to array
Solution
Step 1: Understand postorder traversal for collection
Postorder means visiting left subtree, right subtree, then root, so values must be appended in that order.
Step 2: Choose correct method to collect values
Recursion that appends root after children ensures correct postorder sequence in the array.
Final Answer:
Recursion: left, right, then append root -> Option A
Quick Check:
Append after children = postorder collection [OK]
Hint: Append root after children for postorder array [OK]
Common Mistakes:
Appending root before children (preorder)
Using queue for level order, not postorder
Confusing traversal types
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.