I have begun working with Mathematica for some Graph Theory, and I want to compute the number of spanning trees of all cubic graphs up to 12 vertices. I have found that
GraphData["Cubic", 12]
will give me the cubic graphs with 12 vertices. But how do I compute the number of spanning trees in each of these graphs. A good tutorial for Graph Theory with Mathematica seems impossible to find (I have found many, but none are actually readable). I can find this:
GraphData[8]; Union[GraphData[#, "VertexCount"] & /@ %%]
to compute the number of vertices in all graphs on 8 vertices, but the #-tag is not defined, and &/@%% seems pretty magical.
To help figure out a Mathematica expression, following is useful
Also, try
FullForminstead ofTreeFormSince
GraphDatahas propertySpanningTreeCount, you could doAlternatively, you could get number of spanning trees from Laplacian matrix of the graph using Kirchoff's matrix tree theorem.
The
Dropcommand drops 1st row and 1st column of the matrix, but you could drop any other row/column.To display 12 vertex cubic graphs nicely, with graph name in tooltip and sorted by number of spanning trees, you could do something like this
To get all cubic, connected graphs with up to 12 vertices (disconnected graphs are not interesting since they have 0 spanning trees), do
GraphData[{"Cubic", "Connected"}, ;; 12]If you are doing graph theory with Mathematica, you could find my graph utilities packages helpful, documented here, here, and here. For instance, with
showGraphspackage, you could display all Cubic graphs over 12 vertices that are not connected withshowGraphs[12,"Cubic",!"Connected"]