Graph Geodesic

Author

Eric W. Weisstein
March 26, 2011

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

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

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

Graphic

V5

gr[g_Graph,i_,j_]:=Module[{p=Sort/@Partition[ShortestPath[g,i,j],2,1],v},
v=Union[Flatten[p]];
Graphics[showGraph[g,
PlotStyles->{AbsolutePointSize[6]},
VertexColors->(If[MemberQ[v,#],Red,Black]&/@Range[V[g]]),
EdgeColors->(If[MemberQ[p,#],Red,Black]&/@ToUnorderedPairs[g])]]
]

Show[GraphicsArray[{
gr[FruchtGraph,9,7],
gr[UtilityGraph,1,3],
gr[PetersenGraph,6,9]
}]]

V6

gr[g_Graph,i_,j_]:=Module[{p=Sort/@Partition[ShortestPath[g,i,j],2,1],v},
v=Union[Flatten[p]];
GraphPlot[g,
Method->None,
"VertexColor"->(If[MemberQ[v,#],Red,Black]&/@Range[V[g]]),
"EdgeColor"->(If[MemberQ[p,#],Red,Black]&/@ToUnorderedPairs[g])
]
]

GraphicsRow[{
gr[Graph["FruchtGraph"],9,7],
gr[Graph["UtilityGraph"],1,3],
gr[Graph["PetersenGraph"],6,9]
}]

Options[GraphPlot]