Bird
Raised Fist0

Consider the optimized recursive balance check code. What is the return value of isBalanced when called on an empty tree (root = None)?

medium🧾 Code Trace Q4 of Q15
Tree: Depth-First Search - Balanced Binary Tree
Consider the optimized recursive balance check code. What is the return value of isBalanced when called on an empty tree (root = None)?
AFalse
BRaises an exception
CNone
DTrue
Step-by-Step Solution
Solution:
  1. Step 1: Trace check_height with root = None

    Returns 0 immediately as base case.
  2. Step 2: isBalanced returns check_height(root) != -1 -> 0 != -1 -> True

  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Empty tree is balanced by definition [OK]
Quick Trick: Empty tree height = 0, balanced [OK]
Common Mistakes:
MISTAKES
  • Assuming empty tree is unbalanced or causes error
Trap Explanation:
PITFALL
  • Some candidates forget base case and return False or error on None root.
Interviewer Note:
CONTEXT
  • Checks handling of edge cases in recursion
Master "Balanced Binary Tree" 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