[英]Why finding the longest path in a graph is NP-hard
A longest path between two given vertices s and t in a weighted graph G is the same thing as a shortest path in a graph −G derived from G by changing every weight to its negation.
加权图 G 中两个给定顶点 s 和 t 之间的最长路径与图 -G 中通过将每个权重变为其否定而从 G 导出的最短路径相同。 Therefore, if shortest paths can be found in −G, then longest paths can also be found in G.
因此,如果在-G中可以找到最短路径,那么在G中也可以找到最长路径。
So why is finding the longest path an NP-hard problem if this transformation can reduce it to the shortest path problem?那么,如果这种转换可以将其简化为最短路径问题,那么为什么找到最长路径是一个 NP-hard 问题呢?
After the transformation, we have have these cases:改造后,我们有这些情况:
-G
has a negative cycle, in which case the shortest path in -G
cannot be found -G
有一个负循环,在这种情况下-G
的最短路径找不到-G
does not have a negative cycle, in which case Floy-Warshall or Bellman-Ford algorithm can find the shortest path in -G
in polynomial time -G
没有负循环,在这种情况下,Floy-Warshall 或 Bellman-Ford 算法可以在多项式时间内找到-G
中的最短路径Questions:问题:
Is it correct to say if there is no negative cycle, the problem of finding longest path is not NP-hard?说如果没有负循环,找到最长路径的问题不是NP-hard的问题对吗?
Is it correct to say in the presence of negative cycles, there is still a longest simple path
between nodes which is NP-hard to be found?说在存在负循环的情况下,节点之间仍然存在最长的
simple path
是 NP 难找到的,是否正确?
If so, is it more accurate to say finding the longest simple path in a graph is NP-hard?如果是这样,说在图中找到最长的简单路径是 NP-hard 是否更准确?
If so, because of -G
transformation is it also correct to say that finding the shortest simple path in a graph is also NP-hard?如果是这样,由于
-G
变换,说在图中找到最短的简单路径也是 NP-hard 也是正确的吗?
Edit编辑
This link explains the confusion about longest path problem in more details: https://hackernoon.com/shortest-and-longest-path-algorithms-job-interview-cheatsheet-2adc8e18869此链接更详细地解释了有关最长路径问题的混淆: https : //hackernoon.com/shortest-and-longest-path-algorithms-job-interview-cheatsheet-2adc8e18869
The confusion here is that the Longest Path Problem generally asks for the longest simple path, ie, the longest path without repeated vertices.这里的混淆是最长路径问题通常要求最长的简单路径,即没有重复顶点的最长路径。 For this reason, it can be reduced to the Hamiltonian Path problem, which is known to be NP-hard.
出于这个原因,它可以简化为哈密顿路径问题,这是已知的 NP-hard。
Bellman-Ford and similar algorithms, on the other hand, compute the shortest path in a graph (note: without simple ), ie vertices can be repeated.另一方面,Bellman-Ford 和类似算法计算图中的最短路径(注意:没有simple ),即顶点可以重复。
So your four questions:所以你的四个问题:
-G
, a longest path does not exist at all in G
, because you can just continue walking around the cycle forever.-G
,最长路径完全不存在中G
,因为你可以永远继续走动周期。 A longest simple
path might still exist, but with or without negative cycle, the problem can be reduced to Hamiltonian Path and is therefore still NP-hard.simple
路径可能仍然存在,但无论有没有负循环,问题都可以简化为哈密顿路径,因此仍然是 NP-hard。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.