Common Mistakes

Common errors to avoid

  • Forgetting base case for null nodes: Always handle null before accessing node properties to avoid null pointer errors.
  • Confusing traversal orders: Preorder processes current first, inorder processes current between children, postorder processes current last.
  • Not tracking global state properly: For problems like max path sum, use instance variable or pass reference to track global maximum.
  • Assuming balanced tree: Height can be O(n)O(n) for skewed trees.

Account for worst-case recursion depth.