YUNOVA · Data Structures & Algorithms · Module 11: Advanced dynamic programming
DP on trees
DP on trees
Key points
- Tree DP computes each node's answer from its children's answers using DFS.
- Many problems keep two states per node, such as taken and not taken.
- Rerooting finds the answer for every node as the root in O(n).