Bird
Raised Fist0

Consider the Morris inorder traversal code. What is the output when the input tree is empty (root = None)?

medium🧾 Code Trace Q4 of Q15
Tree: Depth-First Search - Binary Tree Inorder Traversal
Consider the Morris inorder traversal code. What is the output when the input tree is empty (root = None)?
A[]
B[None]
CRuntime error due to null pointer
D[0]
Step-by-Step Solution
Solution:
  1. Step 1: Check initial condition

    current is None, so while loop never executes.
  2. Step 2: Return result list

    result is empty list, so returns [].
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Empty tree yields empty traversal list [OK]
Quick Trick: Empty tree -> empty output list [OK]
Common Mistakes:
MISTAKES
  • Assuming code crashes on None root
  • Returning list with None element
Trap Explanation:
PITFALL
  • Some candidates expect runtime error or non-empty output on empty input.
Interviewer Note:
CONTEXT
  • Tests handling of edge case empty input in traversal code
Master "Binary Tree Inorder 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