[Math] Draw Graph from distance to other nodes

graph theorytrees

I have a matrix that shows the distance from a node to another node:

  A B C D E
A 0 2 4 3 1
B 2 0 2 1 3
C 4 2 0 2 1
D 3 1 2 0 2
E 1 3 1 2 0

To clearify: The 2 at A and B means there are 2 "hops" from A to B like

A ------ X ------ B

X is unknow, it could be anything, even nodes that are not in the list.

Assuming this is a tree graph, how can I draw the graph to this matrix using fewest possible nodes that are not in the matrix?

Best Answer

Assuming that you are talking about simple undirected graphs (so there are no multiple edges, no loops, and if there is an edge between $A$ and $B$ then there is also an edge between $B$ and $A$ - this is equivalent to the matrix you've given being symmetric), then all you need to consider is the position of the $1$'s in your matrix. These tell you the neighbours of a given vertex. Thus by starting with an arbitrary vertex you can draw the graph.

For example in the above you could start with vertex $A$, and then as the entry in row $A$ column $E$ is a $1$, you know that $E$ is a neighbour of $A$. Since this is the only $1$ in row $A$, it will be the only neighbour of $A$.

The other entries in the matrix should just give you "checks", i.e. ways of checking that you have drawn your graph correctly.

However, as pointed out by @Arthur, the matrix you have given is not a valid matrix in this context.

Related Question