Graph Distance

Author

Eric W. Weisstein
May 31, 2004

This notebook downloaded from http://mathworld.wolfram.com/notebooks/GraphTheory/GraphDistance.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/GraphDistance.html.

©2005 Wolfram Research, Inc. except for portions noted otherwise

Figure

Example 1

ShowLabeledGraph[g1=AddEdges[Cycle[5],{{5,2},{5,3}}]]

geodesic=ShortestPath[g1,1,3]

Length[geodesic]-1

Distances[g1,2]

Example 2

ShowLabeledGraph[g2=GridGraph[4,4]]

geodesic=ShortestPath[g,13,8]

Length[geodesic]-1

Together

Show[GraphicsArray[
ShowGraph[#,VertexColor->Red,
DisplayFunction->Identity,
VertexStyle->Disk[.05]]&/@{g1,g2}]]