public class DepthFirstSearch extends Object
DepthFirstSearchclass represents a data type for determining the vertices connected to a given source vertex s in an undirected graph. For versions that find the paths, see
This implementation uses depth-first search.
NonrecursiveDFS for a non-recursive version.
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.
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|
Computes the vertices in graph
|Modifier and Type||Method and Description|
Returns the number of vertices connected to the source vertex
Unit tests the
Is there a path between the source vertex
public boolean marked(int v)
v- the vertex
trueif there is a path,
0 <= v < V
public int count()
public static void main(String args)
args- the command-line arguments