# Why don't the graph “Path” functions (e.g. FindHamiltonianCycle[ ]) work when a graph is specified via its adjacency matrix?

I've defined the function, drawGraph, to display a graph as follows:

drawGraph[g_] := GraphPlot[g, VertexLabeling -> True, DirectedEdges -> True]

If I specify a graph via its edges, and then ask for a hamiltonian cycle, everything works fine as seen below

However if I specify a graph via its adjacency matrix, and then ask for a hamiltonian cycle, I'm told that the adjacency matrix is not a graph. However I can display the adjacency matrix as a graph using my drawGraph[] function as seen below.

Why does the drawGraph function interpret the adjacency matrix as a graph but not the FindHamiltonianCycle function? The same problem exists with all the other Path functions -- ShortestPath, EulerianPath, etc.

• GraphPlot is an obsolete function from the time when Mathematica did not have the Graph data structure, and there was no alternative but to use explicit but limited representations such as adjacency matrices. Having a data structure specifically for representing graphs is generally advantageous for programming. Why wouldn't you just use Graph? – Szabolcs May 16 '18 at 12:09

After further study of the Mathematica documentation, I now see how to define a graph via an adjacency matrix, namely use the AdjacencyGraph[] function as follows:

When g is defined this way the Hamiltonian cycle function works

as do all the other graph functions.

The only problem with using the AdjacencyGraph[] function to define the graph is that although the graph is rendered properly, the vertices are not labeled. The only way I could find to label the vertices was to use the GraphPlot[] function.

The commenter above claimed that GraphPlot[] was obsolete, but obsolete or not, it's still apparently useful.

• AdjacencyGraph is not obsolete; GraphPlot is. You can use  AdjacencyGraph[A, VertexLabels->"Name"] to obtain vertex labels. (A is of course the adjacency matrix.) – Henrik Schumacher May 21 '18 at 11:27
• I said that GraphPlot was obsolete, which it is. I never said that AdjacencyGraph was obsolete. To show labels, use VertexLabels -> "Name". This is shown on the documentation page of Graph. If you want the same style as GraphPlot, use GraphStyle -> "VintageDiagram" – Szabolcs May 21 '18 at 11:29
• @Szabolcs Sorry for writing AdjacencyGraph when I meant to write GraphPlot. It's been corrected it. And Thanks for the GraphStyle hint. – Richard Gostanian May 21 '18 at 13:00