[Math] Find if we can reach all nodes in a directed graph starting from one node s

algorithmsgraph theory

If we have a directed graph $G = (V,E)$ and we want to find if there is such node $s \in V$ that we can reach all other nodes of $G$

What is a good algorithm to solve this problem and what is its execution time?

Best Answer

Run Tarjan's linear-time algorithm for finding strongly connected components.

If there is more than one component with no incoming edges, then there can be no node that can reach everywhere.

On the other hand, if there is exactly one component with no incoming edges, each node in that component (and no other nodes) can reach everywhere in the graph.

(If you're looking for nodes that are reachable from everywhere -- as in the original the title of the question said -- look instead for components with no outgoing edges).