且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

找到两个图节点之间的所有路径

更新时间:2023-01-25 23:38:37

查找所有可能的路径是一个很难的问题,因为有简单的路径指数数。即使找到第k最短路径[或最长路径]有 NP难

Finding all possible paths is a hard problem, since there are exponential number of simple paths. Even finding the kth shortest path [or longest path] are NP-Hard.

一个可能的解决您的所有路径[或所有路径达到一定长度] 取值 T BFS 的,不保持一个访问设置,或加权版本 - 你可能需要使用统一成本搜索

One possible solution to find all paths [or all paths up to a certain length] from s to t is BFS, without keeping a visited set, or for the weighted version - you might want to use uniform cost search

注意,还具有周期每图形[它不是一个 DAG 的]可能存在的路径无限多在取值 T

Note that also in every graph which has cycles [it is not a DAG] there might be infinite number of paths between s to t.