# Wolfram Language & System 10.3 (2015)|Legacy Documentation

This is documentation for an earlier version of the Wolfram Language.
BUILT-IN WOLFRAM LANGUAGE SYMBOL

# GraphDistanceMatrix

gives the matrix of distances between vertices for the graph g.

GraphDistanceMatrix[g,d]
gives the matrix of distances between vertices of maximal distance d in the graph g.

GraphDistanceMatrix[{vw,},]
uses rules to specify the graph g.

## Details and OptionsDetails and Options

• GraphDistanceMatrix returns a SparseArray object or an ordinary matrix.
• The entries of the distance matrix give the shortest distance from vertex to vertex .
• The diagonal entries of the distance matrix are always zero.
• The entry is Infinity () if there is no path from vertex to vertex .
• In GraphDistanceMatrix[g,d], an entry will be Infinity if there is no path from vertex to vertex in d steps or less.
• The vertices are assumed to be in the order given by VertexList[g].
• For a weighted graph, the distance is the minimum of the sum of weights along any path from vertex to vertex .
• The following options can be given:
•  EdgeWeight Automatic weight for each edge Method Automatic method to use
• Possible Method settings include , , and .

## ExamplesExamplesopen allclose all

### Basic Examples  (1)Basic Examples  (1)

Give the distance matrix for a Petersen graph:

 Out[1]//MatrixForm=