Package dsa
Class BFSPaths
java.lang.Object
dsa.BFSPaths
- All Implemented Interfaces:
Paths
An immutable data type to compute the shortest paths between a fixed source vertex and any other vertex in an
undirected graph.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiondouble
distTo
(int v) Returns the shortest distance between a designated source vertex and vertexv
, or infinity.boolean
hasPathTo
(int v) Returnstrue
if there is a path between a designated source vertex and vertex *v
, andfalse
otherwise.static void
Unit tests the data type.pathTo
(int v) Returns a path between a designated source vertex and vertexv
, ornull
.
-
Constructor Details
-
BFSPaths
Computes shortest paths between source vertexs
and every other vertex in the graphG
.- Parameters:
G
- the graph.s
- the source vertex.
-
-
Method Details
-
hasPathTo
public boolean hasPathTo(int v) Returnstrue
if there is a path between a designated source vertex and vertex *v
, andfalse
otherwise. -
pathTo
Returns a path between a designated source vertex and vertexv
, ornull
. -
distTo
public double distTo(int v) Returns the shortest distance between a designated source vertex and vertexv
, or infinity. -
main
Unit tests the data type.- Parameters:
args
- the command-line arguments.
-