Graph Distance

The distance
between two vertices
and
of a finite graph is the minimum length of the paths connecting them (i.e., the length of a graph geodesic). If no such path exists (i.e., if the vertices lie in different connected components), then the distance is set equal to
. In a grid graph the distance between two vertices is the sum of the "vertical" and the "horizontal" distances (right figure above).
The matrix
consisting of all distances from vertex
to vertex
is known as the all-pairs shortest path matrix, or more simply, the graph distance matrix.
REFERENCES
Buckley, F. and Harary, F. Distance in Graphs. Redwood City, CA: Addison-Wesley, 1990.Diestel, R. Graph Theory, 3rd ed. New York: Springer-Verlag, p. 8, 1997.
Wilson, R. J. Introduction to Graph Theory, 3rd ed. New York: Longman, p. 30, 1985.