Each node is given an index (starting at 0). In this case, Node 1 has index 0, Node 2 has index 1, and Node 3 has index 2. To find the weight between a Node with index i
, and a Node with index j
, look at G[i][j]
.
For example, to find the weight between Node 1 and Node 3, you look at the matrix entry G[0][2]
, which is 2.
Because it is an undirected graph, it doesn't matter which node is the start and which is the end, so the top half of the matrix is the same as the bottom half.