Trees
Traverse and manipulate hierarchical structures using DFS (pre/in/post-order) and BFS (level-order) traversals.
- • Hierarchical data
- • BST search/insert
- • Path problems
- • Level-order processing
- • Flat data with no hierarchy
- • Need to visit nodes in arbitrary order
- • Forgetting null checks
- • Confusing pre/in/post-order
- • Not returning values correctly in recursion
Key Invariant
Most tree problems are solved by choosing the right traversal order and passing state through recursion