The Concept
A tree is a hierarchical structure where each node has at most one parent and zero or more children. In a Binary Tree, each node has at most two children (left and right). The power of trees lies in their recursive nature: every subtree is itself a tree, allowing us to solve complex problems by solving the same problem for smaller subtrees.
Worked Example
To find the maximum depth of a tree, you find the max depth of the left subtree and the max depth of the right subtree, and take the larger one plus one (for the current root).
Common Mistakes
- Forgetting the base case (null node)
- Confusing In-order, Pre-order, and Post-order traversals
- Treating a tree as a flat list
Self-Check
How would you check if a binary tree is a valid Binary Search Tree (BST)? What is the key property that must hold for every node?