GraphTheory
Distance
distance between two vertices
Calling Sequence
Parameters
Options
Description
Examples
Compatibility
Distance(G, s, t)
G
-
graph
s, t
vertices of the graph
weighted=truefalse
Specifies whether edge weights should be included in the calculation of weighted distance. The default is false.
Distance returns the number of edges in the shortest path from s to t. If no such path exists, the output is infinity. The strategy is to use a breadth-first search (BFS).
To find a path from s to t with minimum distance use the ShortestPath command.
with⁡GraphTheory:
with⁡SpecialGraphs:
P ≔ PetersenGraph⁡
P≔Graph 1: an undirected graph with 10 vertices and 15 edge(s)
Distance⁡P,1,4
2
ShortestPath⁡P,1,4
1,5,4
DMP ≔ Graph⁡map⁡x→sort⁡convert⁡x,list,Edges⁡P
DMP≔Graph 2: a directed graph with 10 vertices and 15 arc(s)
Distance⁡DMP,1,4
3
ShortestPath⁡DMP,1,4
1,2,3,4
The GraphTheory[Distance] command was updated in Maple 2021.
The weighted option was introduced in Maple 2021.
For more information on Maple 2021 changes, see Updates in Maple 2021.
See Also
AllPairsDistance
BellmanFordAlgorithm
Diameter
DijkstrasAlgorithm
ShortestPath
Download Help Document