Finding the shortest path in a graph without any negative prefixes

后端 未结 9 1858
北荒
北荒 2021-01-31 11:15

Find the shortest path from source to destination in a directed graph with positive and negative edges, such that at no point in the path the sum of edges coming

9条回答
  •  既然无缘
    2021-01-31 11:39

    Admittedly this isn't a constructive answer, however it's too long to post in a comment...

    It seems to me that this problem contains the binary as well as discrete knapsack problems, so its worst-case-running-time is at best pseudo-polynomial. Consider a graph that is connected and weighted as follows:

    Graph with initial edge with weight x and then a choice of -a(i) or 0 at each step

    Then the equivalent binary knapsack problem is trying to choose weights from the set {a0, ..., an} that maximizes Σ ai where Σ ai < X.

    As a side note, if we introduce weighted loops it's easy to construct the unbounded knapsack problem instead.

    Therefore, any practical algorithm you might choose has a running time that depends on what you consider the "average" case. Is there a restriction to the problem that I've either not considered or not had at my disposal? You seem rather sure it's an O(n3) problem. (Although what's n in this case?)

提交回复
热议问题