Class BreadthFirstSearcher
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionsearch
(DirectedGraph<Vertex, Weight> graph, Vertex source) Perform breadth-first search on the given graph from the given vertex.
-
Constructor Details
-
BreadthFirstSearcher
public BreadthFirstSearcher()
-
-
Method Details
-
search
public static <Vertex,Weight> Map<Vertex,Path<Vertex, searchInteger>> (DirectedGraph<Vertex, Weight> graph, Vertex source) Perform breadth-first search on the given graph from the given vertex.Returns a map whose keys are the connected vertices, i.e. the vertices that are reachable starting from the given source, and whose values are information about _how_ they're reachable, i.e. about a path that connects the source to it.
The path information for each connected vertex is (a) the distance between the source and it (since we're ignoring edge weights, this is the number of steps/edges to get from the source to it) using the path found by BFS (which will use the minimum possible number of steps, but may not be the shortest if edge weights are taken into account), and (b) the previous vertex in the path found by BFS.
For example, if the graph is
a -> b -> c -> d e
and the source is b, then the map returned by BFS will beb => null, 0; c => b, 1; d => c, 2;
.- Type Parameters:
Vertex
- the vertex typeWeight
- the weight type (on the edges)- Parameters:
graph
- the graphsource
- the source vertex- Returns:
- information about the vertices reachable from the given source
-