B. Change 'root == NULL' to 'root = NULL' in if condition
C. Remove recursive call to right subtree
D. Move printf before recursive calls to print root first
Solution
Step 1: Analyze traversal order in code
Current code prints after left and right calls, which is postorder (Left, Right, Root).
Step 2: Fix order to preorder
Print root data before recursive calls to get Root, Left, Right order.
Final Answer:
Move printf before recursive calls to print root first -> Option D
Quick Check:
Preorder prints root before children [OK]
Hint: Print root before recursive calls for preorder [OK]
Common Mistakes:
Printing after recursive calls (postorder)
Using assignment '=' instead of comparison '=='
Changing return type unnecessarily
5. You want to collect all node values in preorder traversal into an array instead of printing. Which approach correctly modifies the preorder function in C?
void preorder(Node *root, int *arr, int *index) {
if(root == NULL) return;
// What goes here?
}