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
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.