Click or drag to resize
BreadthFirstPaths Class

The BreadthFirstPaths class represents a data type for finding shortest paths (number of edges) from a source vertex S (or a set of source vertices) to every other vertex in an undirected graph.

This implementation uses breadth-first search. The constructor takes time proportional to V + E, 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.

Inheritance Hierarchy
SystemObject
  Algs4NetBreadthFirstPaths

Namespace: Algs4Net
Assembly: Algs4Net (in Algs4Net.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public class BreadthFirstPaths

The BreadthFirstPaths type exposes the following members.

Constructors
  NameDescription
Public methodBreadthFirstPaths(Graph, IEnumerableInt32)
Computes the shortest path between any one of the source vertices in sources and every other vertex in graph G.
Public methodBreadthFirstPaths(Graph, Int32)
Computes the shortest path between the source vertex s
Top
Methods
  NameDescription
Public methodDistTo
Returns the number of edges in a shortest path between the source vertex s (or sources) and vertex v?
Public methodHasPathTo
Is there a path between the source vertex s (or sources) and vertex v?
Public methodStatic memberMainTest
Demo test the BreadthFirstPaths data type.
Public methodPathTo
Returns a shortest path between the source vertex s (or sources) and v, or null if no such path.
Top
Remarks

For additional documentation, see Section 4.1 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

This class is a C# port from the original Java class BreadthFirstPaths implementation by the respective authors.

See Also