Tree
Key:
Always draw the recursion tree
Recursive rule: because for each node, the value being returned to it and property of its children subtrees are the same, it's easy to set up the recursive rule
Base case (in general): null pointer under the leaf node
Knowing how traversal of a binary tree works. For each node, solve problems on its left child tree and right child tree will most likely solve the problem for the root(original tree)
Basic methods of thinking:
What do you expect from the left child and right child? Usually the return type of the recursive function
What do you do in the current layer of the recursion tree?
What do you report to the parent?
Last updated
Was this helpful?