GraphTheory
ShortestPath
find a shortest path between two vertices
Calling Sequence
Parameters
Description
Examples
ShortestPath(G, u, v)
G
-
graph
u, v
vertices of the graph
ShortestPath(G, u, v) returns a shortest path from u to v in G using a breadth-first search. The output is a list of vertices in the order they appear on the path. If no such a path exists, an error message is displayed.
If G is undirected, the output is a shortest path between u and v. If G is directed, the output is a shortest directed path from u to v.
Edge weights are ignored.
To compute shortest paths with respect to edge weights, use either DijkstrasAlgorithm or BellmanFordAlgorithm.
with⁡GraphTheory:
C6 ≔ CycleGraph⁡6
C6≔Graph 1: an undirected graph with 6 vertices and 6 edge(s)
IsReachable⁡C6,1,5
true
ShortestPath⁡C6,1,5
1,6,5
See Also
BellmanFordAlgorithm
DijkstrasAlgorithm
Distance
IsReachable
Reachable
Download Help Document