public class DirectedDFS extends java.lang.Object
DepthFirstDirectedPaths
and BreadthFirstDirectedPaths
.
This implementation uses depth-first search. The constructor takes time proportional to V + E (in the worst case), 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 |
---|
DirectedDFS(Digraph G,
int s)
Computes the vertices in digraph G that are
reachable from the source vertex s.
|
DirectedDFS(Digraph G,
java.lang.Iterable<java.lang.Integer> sources)
Computes the vertices in digraph G that are
connected to any of the source vertices sources.
|
Modifier and Type | Method and Description |
---|---|
int |
count()
Returns the number of vertices reachable from the source vertex
(or source vertices).
|
static void |
main(java.lang.String[] args)
Unit tests the DirectedDFS data type.
|
boolean |
marked(int v)
Is there a directed path from the source vertex (or any
of the source vertices) and vertex v?
|
public DirectedDFS(Digraph G, int s)
G
- the digraphs
- the source vertexpublic DirectedDFS(Digraph G, java.lang.Iterable<java.lang.Integer> sources)
G
- the graphsources
- the source verticespublic boolean marked(int v)
v
- the vertexpublic int count()
public static void main(java.lang.String[] args)