public class DepthFirstDirectedPaths extends java.lang.Object
This implementation uses depth-first search. The constructor takes time proportional to V + E, where V is the number of vertices and E is the number of edges.
For additional documentation, see Section 4.1 of Algorithms, 4th Edition, by Robert Sedgewick and Kevin Wayne.
Constructor and Description |
---|
DepthFirstDirectedPaths(Digraph G,
int s)
Computes a directed path from s to every other vertex in digraph G.
|
Modifier and Type | Method and Description |
---|---|
boolean |
hasPathTo(int v)
Is there a directed path from the source vertex s to vertex v?
|
static void |
main(java.lang.String[] args)
Unit tests the DepthFirstDirectedPaths data type.
|
java.lang.Iterable<java.lang.Integer> |
pathTo(int v)
Returns a directed path from the source vertex s to vertex v, or
null if no such path.
|
public DepthFirstDirectedPaths(Digraph G, int s)
G
- the digraphs
- the source vertexpublic boolean hasPathTo(int v)
v
- the vertexpublic java.lang.Iterable<java.lang.Integer> pathTo(int v)
v
- the vertexpublic static void main(java.lang.String[] args)