FInding the longest path that is <= x (weighted, undirected graph)

牧云@^-^@ 提交于 2019-12-13 17:55:48

问题


I can't think of any algorithm that would find the longest path, that is smaller or equal to some x variable. With Dijkstra's algorithm I can easily get longest path, however I'm not sure if I can use it in my problem.


回答1:


Dijkstra's algorithm will give you the shortest path, not the longest one.

Finding the longest (simple) path is NP-Hard. Since your problem can be degenerated into the longest path problem (take x equal to the sum of all edge weights, which is an upper bound on the length of the longest path), it is also NP-Hard.

You could still use a tree search, but it is not likely to be tractable.

If you are considering non-simple paths (nodes can be traversed several times) then it is a different problem. A degenerate case is the knapsack problem, which is NP-Hard as well.




回答2:


You can use DFS algorithm in order to found longest path. If you search you can found some useful articles, like Depth First Search & Directed Acyclic Graphs.



来源:https://stackoverflow.com/questions/14182476/finding-the-longest-path-that-is-x-weighted-undirected-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!