I have a graph defined as follow:

r = Graph[{1 <-> 2, 1 <-> 4, 2 <-> 3, 3 <-> 4, 3 <-> 5, 5 <-> 6, 5 <-> 7}, VertexLabels -> "Name"]


then I want to get the adjacency matrix of this graph by using the AdjacencyMatrix function. I doubt the output is incorrect, at least, it is not as I expected

AdjacencyMatrix[r] Take the first row as example, if it corresponds to vertex 1, this row should be

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


Does anyone could help me to explain this output?

• it is correct. The node numbering in the matrix are actually listed as VertexList[r] , which is {1, 2, 4, 3, 5, 6, 7} – Nasser Jan 15 '15 at 9:00

The node numbering in the matrix are actually listed as VertexList[r] , which is {1, 2, 4, 3, 5, 6, 7} I am not sure why Mathematica does it this way, it does not seem natural to me.

r = Graph[{1 <-> 2, 1 <-> 4, 2 <-> 3, 3 <-> 4, 3 <-> 5, 5 <-> 6, 5 <-> 7},
VertexLabels -> "Name"]; To reorder the matrix:

m = AdjacencyMatrix[r];
z = VertexList[r];
m0 = m[[z, z]] // MatrixForm • Probably it does this because you can put as vertices anything you want, also things like images etc. Reordering in such cases would be problematic. – Kuba Jan 15 '15 at 9:16
• It's a so nice explanation. Thank you very much! :-) – fetag Jan 15 '15 at 9:20
• @fetag: If it fully answers your question, feel free to mark it as such by clicking the accepted answer checkmark below the answer score tag. – DumpsterDoofus Jan 15 '15 at 21:53