Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the minimum set of vertices in a Directed Graph such that all other vertices can be reached

Given a directed graph, I need to find the minimum set of vertices from which all other vertices can be reached.

So the result of the function should be the smallest number of vertices, from which all other vertices can be reached by following the directed edges.

The largest result possible would be if there were no edges, so all nodes would be returned.

If there are cycles in the graph, for each cycle, one node is selected. It does not matter which one, but it should be consistent if the algorithm is run again.

I am not sure that there is an existing algorithm for this? If so does it have a name? I have tried doing my research and the closest thing seems to be finding a mother vertex If it is that algorithm, could the actual algorithm be elaborated as the answer given in that link is kind of vague.

Given I have to implement this in javascript, the preference would be a .js library or javascript example code.

like image 904
Ryan Ramage Avatar asked Dec 20 '10 18:12

Ryan Ramage


People also ask

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

Once you have the strongly connected components, the set of vertices reachable from all others is exactly the set of vertices whose strongly connected component(s) have out-degree 0 (the sinks in the graph).

How do you find the minimum number of edges on a graph?

The minimum number of edges for undirected connected graph is (n-1) edges. To see this, since the graph is connected then there must be a unique path from every vertex to every other vertex and removing any edge will make the graph disconnected.

What is the minimum and maximum number of edges in a simple graph of n vertices?

Simple Graph The maximum number of edges possible in a single graph with 'n' vertices is nC2 where nC2 = n(n – 1)/2. The number of simple graphs possible with 'n' vertices = 2nc2 = 2n(n-1)/2.

What is the minimum number of edges in a directed graph with n nodes?

The minimum number of edges in any simple connected graph is “n-1” for “n” vertices.


1 Answers

From my understanding, this is just finding the strongly connected components in a graph. Kosaraju's algorithm is one of the neatest approaches to do this. It uses two depth first searches as against some later algorithms that use just one, but I like it the most for its simple concept.

Edit: Just to expand on that, the minimum set of vertices is found as was suggested in the comments to this post : 1. Find the strongly connected components of the graph - reduce each component to a single vertex. 2. The remaining graph is a DAG (or set of DAGs if there were disconnected components), the root(s) of which form the required set of vertices.

like image 120
kyun Avatar answered Oct 13 '22 06:10

kyun