Bird
Raised Fist0

Given the following Morris preorder traversal code snippet, what is the output list after running it on the tree: root=1, left=2, right=3?

easy🧾 Code Trace Q3 of Q15
Tree: Depth-First Search - Binary Tree Preorder Traversal
Given the following Morris preorder traversal code snippet, what is the output list after running it on the tree: root=1, left=2, right=3?
A[2, 1, 3]
B[1, 2, 3]
C[1, 3, 2]
D[3, 2, 1]
Step-by-Step Solution
Solution:
  1. Step 1: Trace root node (1)

    Append 1, move to left child 2.
  2. Step 2: Visit node 2

    Left is None, append 2, move to right child (None), backtrack to 1's right child 3.
  3. Step 3: Visit node 3

    Left is None, append 3, traversal ends.
  4. Final Answer:

    Option B -> Option B
  5. Quick Check:

    Output matches preorder traversal [OK]
Quick Trick: Morris preorder outputs root-left-right [OK]
Common Mistakes:
MISTAKES
  • Confusing order due to threading pointers
Trap Explanation:
PITFALL
  • Candidates often misinterpret threading steps and output wrong order.
Interviewer Note:
CONTEXT
  • Tests ability to mentally execute Morris traversal on simple tree.
Master "Binary Tree Preorder Traversal" 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