1

A company is planning a party for its employees. A fun rating is assigned to every employee. The employees are organized into a strict hierarchy, i.e. a tree rooted the president. There is one restriction, though, on the guest list to the party: an employee and his/her immediate supervisor (parent in the tree) cannot both attend the party. You wish to prepare a guest list for the party that maximizes the sum of fun ratings of the guests. Show that greedily choosing guests according to fun rating, will not work. Then, formulate a dynamic programming solution

I could not understand some of the conditions like is the fun rate of the president higher than that of his descendants and how many employees are there for each of his supervisor. Can someone help me in proceeding with this ?

2 Answers 2

1

From the phrasing on the problem, the fun rating assigned to someone in the hierarchy tree is not necessarily greater than their descendants in the hierarchy tree.

However, even if this were the case, to see that it is not optimal to pick the best employee, consider a tree of height 2 with a root of fun=10 and 20 children of fun=1. Then the optimal solution is to skip the greedy choice (the root) and choose the 20 children.

In any case, with dynamic programming you can find the best solution even if parents can have lower fun than their descendants. For a node v in the tree, let F(v) be the maximum fun that can be attained within subtree rooted at v. Then either you choose v in which case the children are skipped and you look at all subtrees that are rooted at children of children (taking the sum of max fun over these subtrees, and adding to fun(v)), or you skip v and then you get the maximum fun is the sum of maximum fun over all subtrees rooted at children of v. This gives a linear time dynamic programming algorithm.

Sign up to request clarification or add additional context in comments.

1 Comment

Just as an interesting addition: the question is essentially asking to find an independent set of maximal weight, restricted to trees.
1

For greedy example show a simple counterexample.

    1
    |
 1--3--1
    |
    1

Choosing greedily i.e. first selecting 3 won't allow us to select any other employee. But if we don't select 3, than max will be 4(all 1's). So greedy approach won't work.

For dynamic programming we can formulate problem as selecting a given root of subtree. If we select a node, than none of its children can be selected. However if we don't select the node, than we can either select the child or not select the child.

for all v initialize
  c(v,true) = fun(v)
  c(v,false)= 0

Than use the following recursion to solve the problem

weight(v,true)  = for all children sum( weight(ci,false) ) + fun(i)
weight(v,false) = for all children sum( max(weight(ci,false), weight(ci,true)))

The answer will be max(weight(v,true),weight(v,false)) for root node.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.