public class DepthFirstSearch extends java.lang.Object
DepthFirstPaths
and BreadthFirstPaths
.
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 |
---|
DepthFirstSearch(Graph G,
int s)
Computes the vertices in graph G that are
connected to the source vertex s.
|
Modifier and Type | Method and Description |
---|---|
int |
count()
Returns the number of vertices connected to the source vertex s.
|
static void |
main(java.lang.String[] args)
Unit tests the DepthFirstSearch data type.
|
boolean |
marked(int v)
Is there a path between the source vertex s and vertex v?
|
public DepthFirstSearch(Graph G, int s)
G
- the graphs
- the source vertexpublic boolean marked(int v)
v
- the vertexpublic int count()
public static void main(java.lang.String[] args)