Here is an undirected graph

m = Graph[{1 \[UndirectedEdge] 3, 2 \[UndirectedEdge] 3,

3 \[UndirectedEdge] 4, 4 \[UndirectedEdge] 5,

4 \[UndirectedEdge] 6, 5 \[UndirectedEdge] 7,

6 \[UndirectedEdge] 8}, GraphLayout -> “SpringEmbedding”,

VertexLabels -> “Name”, ImagePadding -> 10]

We can get the Adjacency Matrix as follows

g = AdjacencyMatrix[m]

The Normal Form of the sparse array g is as follows.

In[28]:= Normal[g]

Out[28]= {{0, 1, 0, 0, 0, 0, 0, 0}, {1, 0, 1, 1, 0, 0, 0, 0}, {0, 1,

0, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 1, 1, 0, 0}, {0, 0, 0, 1, 0, 0, 1,

0}, {0, 0, 0, 1, 0, 0, 0, 1}, {0, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0,

0, 1, 0, 0}}

The adjacency matrix does not appear to be correct for the graph m.

=================

=================

1 Answer

1

=================

The ordering of the vertices used for AdjacencyMatrix is that given in VertexList[m]:

ordering={1, 3, 2, 4, 5, 6, 7, 8}

Thus, while it looks like the adjacency matrix is saying that 1 and 2 are joined. If you look at the ordering in VertexList You’ll see that the second element is actually node number 3.