distance between two vertices
Distance(G, s, t)
vertices of the graph
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).
For weighted graphs, the weights of edges are ignored. Use the AllPairsDistance, DijkstrasAlgorithm, or BellmanFordAlgorithm commands to compute weighted distances between vertices.
To find a path from s to t with minimum distance use the ShortestPath command.
P≔Graph 1: an undirected unweighted graph with 10 vertices and 15 edge(s)
DP≔Graph 2: a directed unweighted graph with 10 vertices and 15 arc(s)
Download Help Document
What kind of issue would you like to report? (Optional)