Maximum-weight independent set problem for a path graph

后端 未结 2 1232
[愿得一人]
[愿得一人] 2021-01-15 04:06

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 (blu

相关标签:
2条回答
  • 2021-01-15 04:57
    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.

    0 讨论(0)
  • 2021-01-15 05:03

    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.

    0 讨论(0)
提交回复
热议问题