Loading topic
root_tree helper from the previous chapter, which returns parent, a children-before-parents order, and subtree sizes. Here we cover the design step that comes before3 min readroot_tree helper from earlier chapters, and that you are comfortable with array DP and Big-O analysis. Here you add a second dimension to the state: whether the subtree's root is chosen or not chosen.3 min readroot_tree helper from earlier chapters, which returns parent, a pre-order order, and size. It also assumes you know that walking reversed(order) finishes every child before its parent. You should be comfortable writing a transition from child state3 min readroot_tree helper, which returns parent, a pre-order order, and subtree sizes. You should also know that a * b % m keeps numbers small.3 min readroot_tree helper and the subtree aggregates from earlier chapters.3 min readroot_tree helper from earlier chapters. root_tree returns parent, a pre-order order, and subtree sizes. In every DP so far, each node stored a fixed number of values. Tree knapsack is different. Each node stores a whole table index3 min readbest_rooted_subtree code. It also assumes you can do Big-O analysis by charging cost to elements, and that you know how a post-order traversal visits children before parents.4 min readroot_tree helper from earlier chapters, the reversed pre-order trick for processing children before parents, and how Python sets and dicts behave, including their average O(1) insert and lookup.3 min read