A directed graph G = (V, E) is said to be semi-connected if, for all pairs of vertices u, v in V we have u -> v or v-> u path. Give an efficient algorithm to determine wheth
Amit's soltuin described completely the most efficient approach. I might just add that one can replace step 4 by checking whether there exists more than one topological order of G'. If yes, then the graph is not semi connected. Otherwise, the graph is semi connected. This can be easily incorporated in Kahn's algorithm for finding topological order of a graph.
Another less efficient solution that works in quadratic time is the following.
First, construct another graph G* which is the reverse of the original graph. Then for each vertex v of G, you run a DFS from v in G and consider the set of reachable nodes as R_v. If R_v != V(G), then run another DFS from v in G* and let the set of reachable nodes be R_v. If the union of R_v and R_v is not V(G) then the graph is not semi connected.