AlgoScope

Tree DP

Compute each node's value from its children's values in postorder.

Dynamic programming, technique, advanced
At 20: take 20, skip 0.20: 20/0304050607080current

Tree DP: Pick nodes, none adjacent, maximise the sum

Decision, step 2 of 9

20 is a leaf. Taken, it is worth 20. Skipped, 0. Both go up, because the parent will decide which one it can use.

Cost

Best
O(n)
Average
O(n)
Worst
O(n)
Space
O(h)