Question: Ex . 4 . 2 6 Dynamic Programming, dimension lifting The green and blue tree optimization problem is this. The data is an arbitrary tree
Ex Dynamic Programming, dimension lifting
The green and blue tree optimization problem is this. The data is an arbitrary tree T where each vertex v in T has a preloaded number vdat, and a blank field vcolor. A tree is legally colored if each color field is assigned one of the two colors green or blue, and no tree edge in T connects a blue parent to a blue child. All of the vertices could be green, but a blue parent can only have green children.
The value of a legally colored tree is the sum of the dat numbers for the blue vertices. We can express this as
operatornamevalTsumv text in Ttext vcolorblue v d a t
aWithout peeking into the text: write a recursive dynamic programming specification for the problem of finding largest value that can be computed for operatornamevalT when the colorings are required to be legal.
BIG hint: Write two recursive specifications. One is for operatornameBlestw which gives the best value for the best legal coloring for the subtree rooted by w when w is colored blue, and the other defines operatornameGrestw which does the same when w is colored green. For convience combined with high expressiveness, you might want to use expressions such as
sumv text in operatornameAdjw
which denotes a sum over all children v of w
b How would you store the solutions to already computed subproblems to ensure that the computation is efficient? That is to make the code efficient, you need to use a lookup data structure. So the question is: how should that be done?
Curiously, there is more than one reasonable answer to this question.
c Briefly explain a reasonable way to save the coloring decisions for the vertices that give the best answer.
d Present an efficient pseudocode that computes and prints the numerical solution for this problem, and also prints out the vertex names and colors. It suffices to write "print v or "print v n a m e to print the name of vertex v
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
