Bird
Raised Fist0

Given the following partial inorder_index_map: {3:1, 9:0, 20:3, 15:2, 7:4} and preorder traversal [3,9,20,15,7], which node is the root of the right subtree of the root node 3?

hard🔄 Reverse Engineer Q9 of Q15
Tree: Depth-First Search - Construct Tree from Preorder and Inorder
Given the following partial inorder_index_map: {3:1, 9:0, 20:3, 15:2, 7:4} and preorder traversal [3,9,20,15,7], which node is the root of the right subtree of the root node 3?
A9
B7
C20
D15
Step-by-Step Solution
Solution:
  1. Step 1: Identify root node

    Root is preorder[0] = 3.
  2. Step 2: Find right subtree root

    Right subtree root is next preorder node after left subtree, which is 20.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Right subtree root follows left subtree in preorder [OK]
Quick Trick: Right subtree root is preorder after left subtree nodes [OK]
Common Mistakes:
MISTAKES
  • Confusing left and right subtree roots
Trap Explanation:
PITFALL
  • Candidates pick left child or later nodes incorrectly.
Interviewer Note:
CONTEXT
  • Tests ability to reason backwards from traversal indices
Master "Construct Tree from Preorder and Inorder" in Tree: Depth-First Search

3 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Tree: Depth-First Search Quizzes