这算法由所有outoging路径寻找最近节点从其他的一个可达 [英] Which algorithm to find the nearest node reachable from the other one by all the outoging paths

查看:335
本文介绍了这算法由所有outoging路径寻找最近节点从其他的一个可达的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪个算法你推荐,找出它可以从特定的一个被所有走出节点的路径到达最近的节点。该图是针对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 block which "closes" the 'IF'.

推荐答案

运行,每次一组平行一广度优先搜索从一开始节点的每个出路径,而你检查的节点增加其计数由一。 (注:平行在这里的意思是,你应该为所有的搜索做的距离= 1的评价第一,那么所有的距离= 2,等等 - 这确保了结果你会发现是沿最近任何路径)。请确保你没有遍历图中的周期,如果存在的话。

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.

运行时间为O(N + E),其中N是节点的数目,E是边的数量下游从当前节点。大多数搜索将花费更少的时间,由于提前终止。

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.

这篇关于这算法由所有outoging路径寻找最近节点从其他的一个可达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆