Skip to content

Distance matrix

A distance matrix is somewhat like an adjacency matrix, but instead of simply showing whether two nodes in a network are connected, it provides information about the weight (e.g. distance) between them.

It’s a way of representing a network in a table, where both the rows and columns correspond to the nodes in the network.

An adjacency matrix looks like this:

V1V2V3
V1-AB
V2A-C
V3BC-

Where:

  • The rows and columns represent the nodes (or vertices) in the network.
  • The letters , and $C in the matrix represent the weight (e.g. distance) between the nodes. These could also be dashes.
  • A dash (-) indicates that there is no direct connection between the nodes (or that the verices are the same).

The dashes in the graph above could also be replaced with s to indicate that the distance from a node to itself is zero.

A distance matrix looks like this, for example:

ABCD
A052-
B50-1
C2-07
D-170

This would represent this network:

2
A --- C
5 | | 7
B --- D
1