DAG - Algorithm to ensure there is a single source and a single sink

Viewed 3481

I have to ensure that a graph in our application is a DAG with a unique source and a unique sink.

Specifically I have to ensure that for a given start node and end node (both of which are known at the outset) that every node in the graph lies on a path from the start node to the end node.

I already have an implementation of Tarjan's algorithm which I use to identify cycles, and a a topological sorting algorithm that I can run once Tarjan's algorithm reports the graph is a DAG.

What is the most efficient way to make sure the graph meets this criterion?

4 Answers
Related