There’s an tree with N nodes and N-1 edges (making it a tree). Each node has a weight W(i). How can you select a subtree of size K nodes that still includes the root of the original tree? I have to do this so it minimizes the “cost” of selecting this “subtree”, where cost is defined as the sum of the weights of all edges kept.
I think I’ve done a problem like this before, and it seems like DP/recursion. However, I know how to deal with it when it’s limited to 2 children per node. You’d defined a function cost(n, i) which means the minimum cost of keeping i nodes starting at node n. You’d iterate from i = 0 to n in one of the children, and give the rest to the other child. However, since each node can have an unlimited amount of children, is there a way to deal with this?
Thanks
For a given node, you want to calculate cost(n, i) using cost(n, i) for its children. Number the children from 0..K and you have another dynamic program. At stage j you want to work out the best possible set of cost(n, i) using only children 0..j.
I’ve been thinking about coding something like this while mucking around with machine learning (Just for fun I want to write programs that look for anomalies by fitting two Weka classifiers instead of one). Is that anything like your purpose?