public class DepthFirstDirectedPaths extends 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. It uses extra space (not including the graph) proportional to V.
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(String[] args)
Unit tests the DepthFirstDirectedPaths data type.
|
Iterable<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 Iterable<Integer> pathTo(int v)
v - the vertexpublic static void main(String[] args)
Copyright © 2014. All Rights Reserved.