Problem:
Given a tree with n nodes we have to find the number of nodes under each sub-tree
The root is 1.
Solution:
we can solve this with dynamic programming
- Determine the bottom nodes of the tree (with no children)
- Assign "weight" 1 to each of the bottom nodes
- Build your way up the tree calculating the "weight" of each node (for example a node with 2 children has "weight" 3)
- That's your answer....
Related Problem: