patternMinor
Number of 5-cycles and 6-cycles in a simple graph
Viewed 0 times
simplenumbergraphandcycles
Problem
Is there any formula for computing the number of 5-cycles and 6-cycles in a simple undirected graph?
Solution
I'll suppose that you looking for $k$ -cycle, and in the following $f(k)$ is a computable function which belongs to $O(k!)$.
One simple algorithm is considering all possible k+1 vertices, to check whether they are part of a some cycle or not, this algorithm is $O(|V|^{k+1})$ (If we consider corresponding edge, running time can be improved on sparse graphs). This idea can be improved by using matrix multiplication algorithm, we know that in the level $m$ of (adjacency) matrix multiplication we have the number of paths of length $m$ starting from each node. Then we can calculate $M^k$, this can be done in $O(f(k)\cdot M^{\omega+1})$ (where $M^\omega$ is the lower bound for running time of matrix multiplication for adjacency matrix $M$ of input graph). But converting this to a cycle is a little bit tricky task and you can find one algorithm here, running time of exponential part still is independent of size of graph and is depend to $f$, but sure in the cycle case $f$ is bigger ($k!$ in the first paper). There are faster but more complicated algorithms like what described in this, all of them are consequence of these simple ideas.
P.S: I hope to be clear that the bound that I mentioned is not tight, e.g in both Monien and Alan's papers, upper bounds are better than general thing that I wrote.
One simple algorithm is considering all possible k+1 vertices, to check whether they are part of a some cycle or not, this algorithm is $O(|V|^{k+1})$ (If we consider corresponding edge, running time can be improved on sparse graphs). This idea can be improved by using matrix multiplication algorithm, we know that in the level $m$ of (adjacency) matrix multiplication we have the number of paths of length $m$ starting from each node. Then we can calculate $M^k$, this can be done in $O(f(k)\cdot M^{\omega+1})$ (where $M^\omega$ is the lower bound for running time of matrix multiplication for adjacency matrix $M$ of input graph). But converting this to a cycle is a little bit tricky task and you can find one algorithm here, running time of exponential part still is independent of size of graph and is depend to $f$, but sure in the cycle case $f$ is bigger ($k!$ in the first paper). There are faster but more complicated algorithms like what described in this, all of them are consequence of these simple ideas.
P.S: I hope to be clear that the bound that I mentioned is not tight, e.g in both Monien and Alan's papers, upper bounds are better than general thing that I wrote.
Context
StackExchange Computer Science Q#14185, answer score: 2
Revisions (0)
No revisions yet.