# How to use NumberOfSpanningTrees ?

GROUPS:
 Shenghui Yang 2 Votes Hey there, The documentation page of this function is quite limited. I followed the instruction but following code does not output useful information:Needs["Combinatorica"]NumberOfSpanningTrees[HypercubeGraph[3]]I want to draw the spanning true of a hypercube, do you know any internal functions other than this one?  Thanks
 William Rummler 2 Votes Hey Shenghui,HypercubeGraph returns a SystemGraph, not a CombinatoricaGraph. Try this:Block[{$ContextPath}, Needs@"Combinatorica"]Needs@"GraphUtilities"CombinatoricaNumberOfSpanningTrees@ ToCombinatoricaGraph@HypercubeGraph@3(* Out: 384 *)--William Answer 5 years ago  Shenghui Yang 2 Votes Definitely two thumbs up to the workaround !My secound question would be what this 384 means? I think I can only draw several (not full set but definitely not more than 10) spanning trees for a 3-cube graph, per my understanding, it is just a set of edges of 3-D cube, right? Answer 5 years ago  William Rummler 1 Vote The output of 384 refers to the number of spanning trees in the 3-hypercube graph. A spanning tree is basically a connected acyclic subset of edges in the graph such that each vertex in the graph is incident on at least one edge in the subset. (Kirchoff's Theorem gives a very nice and efficient algorithm for computing the number of spanning trees, and Combinatorica.m uses that approach.)You can use Combinatorica's MinimumSpanningTree to get at least one MST. To get other ones, you could delete an edge you would like to avoid and put the edge-deleted graph through MinimumSpanningTree again. That feels kind of hacky, but it is easy enough to do for only ~10 MSTs if you just need them quickly. Block[{$ContextPath}, Quiet@Needs@"Combinatorica"]  Needs@"GraphUtilities"  g = HypercubeGraph@3;  cg = CombinatoricaMakeUndirected@ToCombinatoricaGraph@g;  mst = CombinatoricaMinimumSpanningTree@cg;CombinatoricaShowGraph@mstAdjacencyGraph@CombinatoricaToAdjacencyMatrix@mst
 IGraph/M now includes a function to count spanning trees. In[1]:= Needs["IGraphM"] During evaluation of In[1]:= IGraph/M 0.3.99.1 (May 1, 2018) During evaluation of In[1]:= Evaluate IGDocumentation[] to get started. In[2]:= IGSpanningTreeCount[HypercubeGraph[3]] Out[2]= 384 To explore the topic, you might find it useful to generate some more random spanning trees and visualize them. g = HypercubeGraph[3, VertexLabels -> Automatic] IGRandomSpanningTree[g, 20] // DeleteDuplicatesBy[AdjacencyMatrix] // Map[HighlightGraph[g, #, GraphHighlightStyle -> "Thick"] &] While this graph has 384 distinct labelled spanning trees, only 6 of them are non-isomorphic. IGRandomSpanningTree[HypercubeGraph[3], 100] // DeleteDuplicatesBy[CanonicalGraph] `