Group Abstract Group Abstract

Message Boards Message Boards

How to use NumberOfSpanningTrees ?

GROUPS:
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
POSTED BY: Shenghui Yang
Answer
11 months ago
Hey Shenghui,

HypercubeGraph returns a System`Graph, not a Combinatorica`Graph. Try this:

Block[{$ContextPath}, Needs@"Combinatorica`"]

Needs@"GraphUtilities`"

Combinatorica`NumberOfSpanningTrees@
ToCombinatoricaGraph@HypercubeGraph@3

(* Out: 384 *)

--William
POSTED BY: William Rummler
Answer
11 months ago
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? 
POSTED BY: Shenghui Yang
Answer
11 months ago
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 = Combinatorica`MakeUndirected@ToCombinatoricaGraph@g;
 
 mst = Combinatorica`MinimumSpanningTree@cg;

Combinatorica`ShowGraph@mst

AdjacencyGraph@Combinatorica`ToAdjacencyMatrix@mst

POSTED BY: William Rummler
Answer
11 months ago
Very handy!! This is definitely more flexible than what I have done manually with EdgeStyle: 
HypercubeGraph[3,
EdgeStyle -> {1 \[UndirectedEdge] 5 -> {Blue, Thick},
   6 \[UndirectedEdge] 5 -> {Blue, Thick},
   2 \[UndirectedEdge] 6 -> {Blue, Thick},
   2 \[UndirectedEdge] 4 -> {Blue, Thick},
   4 \[UndirectedEdge] 8 -> {Blue, Thick},
   8 \[UndirectedEdge] 7 -> {Blue, Thick},
   7 \[UndirectedEdge] 3 -> {Blue, Thick}}]

POSTED BY: Shenghui Yang
Answer
11 months ago