GraphDistanceMatrix

As of Version 10, all the functionality of the GraphUtilities package is built into the Wolfram System. >>

GraphDistanceMatrix[g]
gives a matrix in which the ^(th) entry is the length of a shortest path in g between vertices i and j.


returns a three-dimensional matrix in which the ^(th) entry is the length of a shortest path from i to j and the ^(th) entry is the predecessor of j in a shortest path from i to j.

Details and OptionsDetails and Options

ExamplesExamplesopen allclose all

Basic Examples  (2)Basic Examples  (2)

In[1]:=
Click for copyable input

This defines a simple directed graph:

In[2]:=
Click for copyable input
In[3]:=
Click for copyable input
Out[3]=

This calculates the distance between the vertices:

In[4]:=
Click for copyable input
Out[4]//MatrixForm=

This function has been superseded by GraphDistanceMatrix in the Wolfram System:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]//MatrixForm=