Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find a vertex that all other vertices can be reached from in a digraph

Given a directed graph, how can we determine whether or not there exists a vertex v, from which all other vertices are reachable. the algorithm should be as efficient as possible.

I know how to do it if we are checking for a given vertex; we could do dfs on the reverse graph. But for this question, it seems inefficient to do it for every vertex in the graph.

Is there a better way?

like image 729
Jake Avatar asked Jan 05 '14 20:01

Jake


People also ask

How can I find the node in a graph that is reachable from every other node in the graph?

One straight forward solution is to do a BFS traversal for every node present in the set and then find all the reachable nodes.

How many vertices does a digraph have?

A digraph is called a tournament for every two vertices, the di- graph contains exactly one directed edge. Let G be a digraph of the outdegree k for some integer k > 0 whose edges are labeled with symbols a1,a2,...,ak so that for every vertex x ∈ V (G), the labels on the edges leaving x are a1,a2,...,ak.

How do you find the reachable node on a graph?

This can be done by first finding Strongly Connected Components (SCC), which can be done in O(|V|+|E|) . Then, build a new graph, G' , for the SCCs (each SCC is a node in the graph), where each node has value which is the sum of the nodes in that SCC.

Is a vertex reachable from itself?

The length of the path is the number of edges, k. We say that w is reachablereachableIn graph theory, reachability refers to the ability to get from one vertex to another within a graph. A vertex can reach a vertex (and is reachable from ) if there exists a sequence of adjacent vertices (i.e. a walk) which starts with and ends with .https://en.wikipedia.org › wiki › ReachabilityReachability - Wikipedia from u if there is a path from u to w. Note that every vertex is reachable from itself by a path that uses zero edges.


1 Answers

Use Kosaraju's algorithm to find the strongly connected components of the graph in time O(|V|+|E|). If you then "shrink" each component to a single node, you'll be left with a directed acyclic graph. There exists a vertex from which all others can be reached if and only if there is exactly one vertex in the DAG with in-degree 0. This is the vertex you're looking for - the so-called "mother vertex".

Note: This answer originally recommended using Tarjan's algorithm. Tarjan's is likely to be a bit faster, but it's also a bit more complex than Kosaraju's.

like image 53
Andy Jones Avatar answered Oct 25 '22 15:10

Andy Jones