2

While taking the Algorithms: Design and Analysis II class, one of the questions asks about the maximum-weight independent set problem for a path graph. shown below is a (blurry) screenshot of the problem statement, and the corresponding lecture videos are on YouTube:

https://www.youtube.com/watch?v=0awkct8SkxA

https://www.youtube.com/watch?v=pLOkbHGRsv0

https://www.youtube.com/watch?v=Im_zjFkZDCY enter image description here

This problem can be elegantly solved by dynamic programming, with literally one line of code.

a[i] = max(a[i - 1], a[i - 2] + w[i])

The question is as follows:

Which of the following is true for our dynamic programming algorithm for computing a maximum-weight independent set of a path graph? (Assume there are no ties.)

  • As long as the input graph has at least two vertices, the algorithm never selects the minimum-weight vertex.
  • The algorithm always selects the maximum-weight vertex.
  • If a vertex is excluded from the optimal solution of two consecutive subproblems, then it is excluded from the optimal solutions of all bigger subproblems.
  • If a vertex is excluded from the optimal solution of a subproblem, then it is excluded from the optimal solutions of all bigger subproblems.

Turns out, the correct answer is #3, which is somewhat intuitive, since the optimal solution to a subproblem depends only on the solutions of the previous two subproblems. But it's not clear to me why options 1 and 2 are incorrect. Since the algorithm looks at all the vertices, it seems both of those options should be correct too.

Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219
  • What would the equation/solution be if the problem were to be modified to find the max IS in a cycle C with n vertices v1. . . vn (for every i < n, vi is connected to vi + 1, vn is connected to v1 and these are the only edges in C). – Red Apple Nov 23 '20 at 09:47
  • @RedApple Ask a new question, don't hijack this one. – Abhijit Sarkar Nov 23 '20 at 09:48

2 Answers2

2

OP here: Here's a full answer for completeness sake, inspired by @robert-king's answer.

Consider the path 10-2-1-4. The vertices selected by the algorithm are 10, 1, where 1, the minimum, is selected. Thus, option 1 is incorrect.

Consider the path 1-3-10-9. The vertices selected by the algorithm are 3, 9, where the maximum 10 isn't selected. Thus, option 2 is incorrect.

Consider the path 1-9-7-1-5. The vertices selected by the algorithm are 1, 7, 5. However, 7 was not included in the optimal solution of the subproblem 1-9-7. Note that, 7 was not included in the optimal solution of the subproblem 1-9-7-1 either, because the its previous vertex was "heavier", and since all weights are positive, the sum of the next weight and the heavier vertex is certainly greater than 7. Thus, option 4 is incorrect.

Option 3 is correct. This follows from induction, since the optimal solution to a subproblem depends only on the solutions of the previous two subproblems.

Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219
1
the algorithm never selects the minimum-weight vertex.

Consider: **3-100-4-1-5-100-6 it makes sense to choose 1, the minimum, since we want to choose the two 100's

The algorithm always selects the maximum-weight vertex.

Consider: 5-99-100-99-7

It makes sense to exclude the maximum in favour of the to 99's

For both these examples, try see what the algorithm would do and why it works.

A good way of reasoning about these types of problems is to try all permutations of (0,0,0,1,1,1,2,2,2,3,3,3,99,99,99,100,100,100) and it should give you most of the posibilities.

Rusty Rob
  • 16,489
  • 8
  • 100
  • 116
  • Your counter examples have ties, which is not allowed by the question. The first three entries of `a` would be `0`, `2`, and `max(2, 0 + 2)` - the last one isn't allowed. – Abhijit Sarkar Dec 25 '18 at 00:21
  • Once I understood the selection logic better, I was able to come up with my own counterexamples. `10-2-1-4` when min is selected, and `1-3-10-9` when max isn't. I'll accept your answer because it lead me to a better understanding. – Abhijit Sarkar Dec 25 '18 at 01:43