简体   繁体   English

找到有向图的顶点在时间O(| E | + | V |)中可到达的所有顶点

[英]Find all vertices reachable from a vertex of a directed graph in time O(|E| + |V|)

Where |E| | E | denotes the number of edges, |V| 表示边数,| V | the number of vertices. 顶点数。

My idea is to use depth-first search on the given vertex to find all vertices reachable from it. 我的想法是在给定的顶点上使用深度优先搜索来找到所有可到达的顶点。 However as far as my understanding goes, performing depth-first search from only one vertex requires O(1 + out-degree(u)) time, where u is the vertex in question. 但是据我所知,仅从一个顶点执行深度优先搜索需要O(1 + out-degree(u))时间,其中u是所讨论的顶点。

Assuming that depth-first search is the answer, why would I have to perform a full O(|V| + |E|) search? 假设深度优先搜索是答案,为什么我必须执行完整的O(| V | + | E |)搜索?

If you perform only one step of the DFS then it is O(1 + outdegree(v)), nevertheless, that will only get you the vertices that are reachable from v at one step, but not all the vertices that you may reach. 但是,如果仅执行DFS的一个步骤,则它是O(1 + outdegree(v)),这只会使您一步就可以从v获得顶点,但不能获得您可能到达的所有顶点。

Think of the recursion, in order to retrieve all reachable vertices you should perform another recursive DFS search for each reached vertex. 考虑一下递归,为了检索所有可到达的顶点,您应该对每个到达的顶点执行另一个递归DFS搜索。 In the worst case you will reach all vertices and thus you will have the sum of O(1+outdegree(v)) for each vertex, so you will traverse all the edges of the graph and get O(|V|+|E|). 在最坏的情况下,您将到达所有顶点,因此每个顶点的总和为O(1 + outdegree(v)),因此您将遍历图形的所有边并获得O(| V | + | E |)。

Because 因为

(1) you must perform a depth-first search not only in the initial vertex, but also in all vertices that are directly connected to it, and in all vertices those vertices are connected to, and so on. (1)您不仅必须在初始顶点中,而且在与其直接连接的所有顶点以及与这些顶点相连的所有顶点中,都执行深度优先搜索。

(2) in the worst case, all the vertices will be reachable from the initial one, and it will be equivalent to perform a full DFS. (2)在最坏的情况下,所有顶点从初始顶点都是可到达的,并且等效于执行完整的DFS。

暂无
暂无

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

相关问题 在有向图中查找每个顶点的可到达顶点 - Finding reachable vertices for every vertex in a directed graph 设计一个O(| V | + | E |)时间算法,该算法可找到有向图的根顶点(或报告不存在) - Design a O(|V | + |E|) time algorithm that finds a root vertex (or reports that none exists) of a directed graph 有向图 - 如何计算图中每个其他顶点可到达的顶点数? - Directed Graph - How to count the number of vertices from which each other vertex in graph is reachable? 令 G=(V, E) 有向图。 设 v 是 G 中的一个顶点,找出参与到 v 的非简单有向路径的顶点数 - Let G=(V, E) directed graph. Let v be a vertex in G, find the number of vertices that take part in non-simple directed paths to v 在有向图中查找可到达的顶点 - Finding reachable vertices in directed graph 在有向图中查找所有其他节点均可访问的节点 - Find nodes in directed graph that is reachable from all other nodes 如何找到有向图中2个特定顶点之间的所有可能路径中存在的顶点? - How to find vertices exist in all possible route between 2 specific vertex in a directed graph? 在所有可达顶点中找到最有价值的顶点 - find the most valuable vertex among all reachable vertices 有向图中的顶点,因此存在从该顶点到其他顶点的路径 - Vertices in directed graph such that there exists a path to every another vertex from this one 如何在O(n + m)的有向图中找到母顶点? - How to find mother vertex in a directed graph in O(n+m)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM