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.4.26 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 v.dat, and a blank field v.color. 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
\[
\operatorname{val}(T)=\sum_{v \text { in } T,\text { v.color=blue }} v . d a t .
\]
a)Without peeking into the text: write a recursive dynamic programming specification for the problem of finding largest value that can be computed for \(\operatorname{val}(T)\) when the colorings are required to be legal.
BIG hint: Write two recursive specifications. One is for \(\operatorname{Blest}(w)\) 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 \(\operatorname{Grest}(w)\) which does the same when \( w \) is colored green. For convience combined with high expressiveness, you might want to use expressions such as
\[
\sum_{v \text { in }\operatorname{Adj}[w]}
\]
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 \).
Ex . 4 . 2 6 Dynamic Programming, dimension

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!