简体   繁体   English

有效地找到有向图中两个节点之间某个路径上的所有节点

[英]Efficiently finding all nodes on some path between two nodes in a directed graph

I'm currently trying to figure out an efficient way to find all nodes on some path between two nodes (say, X and Y ) in a directed graph. 我目前正在尝试找出一种有效的方法,以在向图中找到两个节点(例如XY )之间的某个路径上的所有节点。

My first thought was to run a BFS from X, run a BFS from Y, and take the intersection of visited nodes. 我的第一个想法是从X运行BFS,从Y运行BFS,并采用被访问节点的交集。 Note that I don't need to enumerate all paths between X and Y, just find all nodes that lie on a path from X to Y. 请注意,我不需要枚举X和Y之间的所有路径,只需查找从X到Y的路径上的所有节点。

My question is, is there a more optimized way to do this? 我的问题是,是否有更优化的方法来做到这一点?

Optimization can be done in terms of getting better run-time or using less memory, or finding a good solution (sometimes a local maximum is ok). 可以从获得更好的运行时或使用更少的内存或找到一个好的解决方案的角度来进行优化(有时可以使用局部最大值)。

You can look at A* search and see if this can be applied to your problem. 您可以查看A *搜索 ,看看是否可以将其应用于您的问题。 You would save both memory and shorten the run-time if you can apply this. 如果可以应用,可以节省内存并缩短运行时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM