Algorithm to check if there's a vertex where all other vertices are reachable from it.

698 Views Asked by At

Let a connected and directed graph $G=(V,E)$. I'm trying to understand a relatively simple algorithm to check if there's a vertex such that any other vertex is reachable from it.

The algorithm is going like this: Look at the "Opposite graph" (edges are at opposite direction). Start a BFS scan from an arbitrary node and find a leaf in the BFS tree. Let's call it $w$.

Now, run from $w$ a BFS scan on the original graph. Check if all vertices were scanned. If so, $w$ is the desired vertex.

I only partially understand why this algorithm works and I'd be glad for an explanation.

Thanks