简体   繁体   中英

Maximum Count Of Cycles In An Undirected Graph

So we are given an undirected graph G=(V, E) with n vertices.

(|V| = n)

How can I find the maximum count of simple cycles in the specified graph G?

I would be really glad if someone could help me by explaining.

So we want to find all possible cycles in the graph. Lets assume every vertex is connected, since that'll generate all edges possible. Now lets start from the simple case, and work our way up.

Let us start with a cycle of length 3. This is the smallest simple cycle we can have in our graph. Any three vertices in our graph can make such a cycle. Order does not matter for this case, because every vertex in our set of three will connect to the other two. So the number of simple cycles of length three will be the number of ways we can select three vertices from a set of V vertices, ignoring order. This is "n choose k" or nck(3, V) , where nck is:

function nck(k, n):
    return factorial(n) / (factorial(k) * factorial(n - k))

That solves the number of cycles of length 3 for us. We can repeat similar logic for length 4, but a new problem emerges. For a group of four vertices a, b, c, d , there's more than one way to connect them in a cycle. We could connect b to a and d , a and c , or c and d . In short, we need to find the number of permutations of these vertices k! , and apply two corrections. First, we'll divide by two to account for permutations that "flip" the order of another permutation (which still would connect the same adjacent vertices). Secondly, we'll divide by k , to account for permutations that merely rotate another permutation (which again, doesn't change which vertices are adjacent to each other). So the number of distinct orderings of a cycle of k vertices is:

function orderings(k):
    return factorial(k - 1) / 2

Now we can compute the number of cycles with length 4 by nck(4, V) * orderings(4) . This process can now be generalized to all length cycles, up to and including V .

To get the total number of cycles, we'll need to sum all of the number of cycles of lengths [3, V] inclusive. Note that we can do a bit of simplification by canceling terms from our two functions. If we write factorial(k - 1) as factorial(k) / k , and inline the two functions, factorial(k) will cancel. We then just need to divide by 2 * k * factorial(n - k) . You could also simplify factorial(n) / factorial(n - k) as simply the product of all integers in [k + 1, n] inclusive, to avoid division by a large factorial.

Overall, this shouldn't be too expensive to compute. By computing factorial(n) / factorial(n - k) in ascending order, we can even avoid recomputing the partial products or any factorials. This means we can count the total number of cycles in linear time. In python:

def cycles(v):
    count = 0
    product = v * (v - 1) * (v - 2) // 2
    for k in range(3, v + 1):
            count += product // k
            product *= (v - k)
    return count

Note that I did try to find a closed-form solution, without any luck. If we didn't have to multiply by the orderings of each cycle, we could compute the cardinality of the powerset of those vertices (minus the number of size 0..2 subsets). I also tried to see if [wolfram alpha]( https://www.wolframalpha.com/input/?i=sum+from+k%3D3+to+v+of+(v%5E2+%2F+2)+%2F+((vk)%5E2+ *+k) could simplify it, but it gave me something even more complex.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM