Trees
Recursive structure where almost every solution is solve the children, then combine.
Newinterview weight 9035 problems2 visualisers
18
mastery
Attempts logged
0
Predicted success on the next one
33%
Solved here
0 / 35
What you actually need to hold in your head
- Pre, in and post order are one walk with different visit times
- BFS by level with a queue
- Return more than one value to the parent
- Height, diameter and path sums are all post-order
Comfortable with these first
Next in the path
Binary Search Tree
Watch it run
Step through the algorithm before you write it.
Patterns in this topic
The trigger phrases are what you are training yourself to notice.
Tree DFS (divide and combine)O(n) time, O(h) stack
Recurse into both children, then combine their answers into the answer for this node. Most tree problems are a post-order fold.
heightdiameter
Tree BFS (level order)O(n) time, O(width) space
Process the queue one full level at a time by snapshotting its length before the loop.
level orderright side view
Trees problems
Ordered by sheet phase, so the early ones are the highest signal.
0 / 35 solved