Chapter
Binary Trees
Tree questions look like a catalogue of unrelated puzzles. They are not. Nearly every one is the same three-line walk with a different line in the middle, and this chapter is about the small number of decisions that vary.
Start with the theory6 short chapters, then the problems in order.
Problems
- Maximum Depth of Binary TreeLC 104 · Post-order · answer built from children
- Invert Binary TreeLC 226 · Post-order · same walk, different work
- Binary Tree Level Order TraversalLC 102 · BFS · one row at a time
- Validate Binary Search TreeLC 98 · Pre-order · pass bounds down
- Lowest Common Ancestor of a Binary TreeLC 236 · Post-order · report findings upward
- Construct Binary Tree from Preorder and InorderLC 105 · Divide and conquer · split by the root
- Binary Tree Maximum Path SumLC 124 · Post-order · return one thing, record another