WLJS LogoWLJS Notebook

GraphDistanceMatrix

GraphDistanceMatrix[g] gives the matrix of shortest path distances between all pairs of vertices.

Examples

Distance matrix of a path:

GraphDistanceMatrix[PathGraph[{1, 2, 3, 4}]]
(* {{0, 1, 2, 3}, {1, 0, 1, 2}, {2, 1, 0, 1}, {3, 2, 1, 0}} *)

For a complete graph:

GraphDistanceMatrix[CompleteGraph[4]]

Please visit the official Wolfram Language Reference for more details.

On this page