Skip to content
StackDecode
Dynamic programmingExplained

Tree DP

Compute each node’s answer from its children’s answers.

Time

O(n)

Extra space

O(n)

Use it for

Independent sets, subtree queries.

An animated walkthrough for this algorithm isn’t built yet. The summary above explains the idea; see the related animated algorithms below to practise the same technique.