This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.

# GraphDistance

 GraphDistance gives the distance from source vertex s to target vertex t in the graph g. GraphDistancegives the distance from s to all vertices of the graph g.
• GraphDistance will give the length of the shortest path between s and t.
• The distance is Infinity when there is no path between s and t.
• For a weighted graph, the distance is the minimum of the sum of weights along any path between s and t.
Give the distance for a grid graph:
Give the distance for a grid graph:
 Out[1]=
 Out[2]=
 Scope   (4)
GraphDistance works with undirected graphs:
Directed graphs:
Weighted graphs:
The distance between two vertices is the smallest total edge weight along any path:
Works with large graphs:
 Options   (3)
The method is automatically chosen depending on input:
method will use the weight 1 for every edge:
can be used for graphs with positive edge weights only:
 Applications   (5)
Find the distance between opposite corners of a GridGraph of size :
Find the distance between opposite corners in a -dimensional GridGraph of size :
Visualize distance from a vertex in a tree:
Obtain the maximum distance from the vertex to any other vertex:
Set color proportionally to distance:
The expected distance between two vertices for Bernoulli graphs with probability is :
Illustrate the DamerauLevenshteinDistance for short words over a small alphabet:
Find the Damerau-Levenshtein distance between two words:
Check the result:
The distance between two vertices can be found using FindShortestPath:
Distance matrix:
In a connected graph, the VertexEccentricity can be computed using GraphDistance:
The distance between two vertices belonging to different connected components is Infinity:
New in 8