graph - Dijkstra for The Single-Source Longest Path

前端 未结 3 1261
滥情空心
滥情空心 2020-12-01 21:34

Ok, I posted this question because of this exercise:

Can we modify Dijkstra’s algorithm to solve the single-source longest path problem by changing mi

相关标签:
3条回答
  • 2020-12-01 21:48

    No, we cannot1 - or at the very least, no polynomial reduction/modification is known - longest path problem is NP-Hard, while dijkstra runs in polynomial time!

    If we can find a modfication to dijsktra to answer longest-path problem in polynomial time, we can derive P=NP

    If not, then provide a counterexample.

    This is very bad task. The counter example can provide a specific modification is wrong, while there could be a different modification that is OK.
    The truth is we do not know if longest-path problem is solveable in polynomial time or not, but the general assumption is - it is not.


    regarding just changing the relaxation step:

            A
           / \
          1   2
         /     \
        B<--1---C
    edges are (A,B),(A,C),(C,B)
    

    dijkstra from A will first pick B, and then B is never reachable - because it is out of the set of distances.

    At the very least, one will have also to change min heap into max heap, but it will have a different counter-example why it fails.


    (1) probably, maybe if P=NP it is possible, but it is very unlikely.

    0 讨论(0)
  • 2020-12-01 21:51

    Yes, we can. And your answer is almost correct. Except one thing.

    You assume no negative weights. In this case Dijkstra's algorithm cannot find longest path.

    But if you assume only negative weights, you can easily find the longest path. To prove correctness, just take absolute values of all weights and you get exactly the usual Dijkstra's algorithm with positive weights.

    0 讨论(0)
  • 2020-12-01 21:59

    It works in directed acyclic graphs but not in cyclic graphs. Since the path will back track and there is no way of avoiding that in dijkstra's algo

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