0

I have a problem. I am trying to count all the spanning trees in a graph(it doesn't have multi edges). I know that there is Kirchhoff's theorem, which lets me count it in quite an easy way, but I prefer a solution which uses cycles in this graph.

I tried to figure out how cycles affect the number of spanning trees, and I have found that when there is a cycle(without additional edges) we can simply delete one of the edges, and we will get a spanning tree. When there are n cycles jointed just by one node, we can just multiply the numbers of edges in every cycle and that is our result. The problem is when two cycles are jointed with more than just one node(for example 1 or 3 edges). I was trying to write an equation, which will let me count this number, and the only thing I got is c1*c2-s^2, where c1 is a size of cycle nr. 1, c2 is a size of cycle nr.2 and s is the number of their common edges. However it doesn't work in some cases. I attach an example below: complete graph

We know that the number of spanning trees in a complete graph is n^(n-2), so we know that it has 16 possible spanning trees. However my algorithm finds 20 of them. Here is why:

I find 3 cycles: (3,4,2),(4,2,1), and (3,4,2,1). then I just use my equation for cycle nr 1 and 2 (3* 3-1), which gives me 8, and at the end I use it one more time with the last cycle (8*3-4 [it has 2 common edges]) which gives me 20. I also have to add that my cycle finding algorithm does not always find a simple cycle.

Could somebody tell me where the mistake is, and how to fix it? Thanks in advance.

manez
  • 1
  • Where is the mistake in what? You didn't actually tell us what your cycle-finding algorithm is, only something about a property that it doesn't have (it doesn't always find a simple cycle). A 4-vertex complete graph has 5 cycles, 4 of them simple, but apparently your algorithm only finds 3 them -- ? – j_random_hacker Apr 25 '21 at 12:17
  • It uses graph-coloring DFS, but I don't really think that I need all of the cycles. In my opinion I need cycles which include all of the edges which are in a cycle. The mistake should be smoewhere in the equation or my method. – manez Apr 25 '21 at 12:20
  • 1
    I think cycles can interact in complex ways, so I don't expect an equation that works for 2 cycles to generalise to arbitrary graphs in a straightforward way. – j_random_hacker Apr 25 '21 at 12:42
  • 1
    Agree with j_random_hacker. You could use the [deletion-contraction formula](https://en.wikipedia.org/wiki/Deletion%E2%80%93contraction_formula#Spanning_trees). But probably we could give better advice if we knew why Kirchhoff is unacceptable. – David Eisenstat Apr 25 '21 at 12:47
  • In particular there are ways to compute the determinant exactly without roundoff. – David Eisenstat Apr 25 '21 at 12:54
  • I just want to know if there is way to count it using cycles cycles. – manez Apr 25 '21 at 13:05
  • But I conclude that there is no easy way to count spanning trees without using Kirchhoff – manez Apr 25 '21 at 13:13

0 Answers0