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 possibl
The solution can be found by taking the concept from Kosaraju's algorithm for Strongly Connected Components. The idea is based on the following fact:
If there exists a vertex (or vertices), from which all other vertices are reachable, then this vertex would have the maximum finish time in a DFS traversal. So, the solution would look like:
// Utility function to find mother vertex
//(vertex from which all other vertices are reachable)
public void findMotherVertex() {
int motherVertex=0;
for (int i=0;i
The above algorithm takes O(V+E) time to solve the problem.