开发者

Which algorithm to find the nearest node reachable from the other one by all the outoging paths

开发者 https://www.devze.com 2022-12-26 00:44 出处:网络
Which algorithm do you recommend to find out the nearest node which can be reached from the specific one by all the paths coming out the node. The graph is directed unweight.

Which algorithm do you recommend to find out the nearest node which can be reached from the specific one by all the paths coming out the node. The graph is directed unweight.

I'm trying to analyze control flow diagram and when there is a 'IF' block I want to find the bloc开发者_JAVA百科k which "closes" the 'IF'.


Run a set of breadth-first searches in parallel, one from each out-path of the start node, and each time you examine a node increment its count by one. (Note: "parallel" here means that you should do all of the "distance = 1" evaluations for all searches first, then all of the "distance = 2", et cetera - this ensures that the result you find is the nearest along any path). Make sure you don't loop through cycles in the graph, if any exist.

Stop on the first node you increment to a count that is the same as the number of out-paths from the original node.

Running time is O(N+E) where N is the number of nodes and E is the number of edges downstream from the current node. Most searches will take less time due to early termination.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号