A General Purpose Algorithm for Counting Simple Cycles and Simple Paths of Any Length

We describe a general purpose algorithm for counting simple cycles and simple paths of any length $$\ell $$ℓ on a (weighted di)graph on N vertices and M edges, achieving an asymptotic running time of $$O\left( N+M+\big (\ell ^\omega +\ell \Delta \big ) |S_\ell |\right) $$ON+M+(ℓω+ℓΔ)|Sℓ|. In this expression, $$|S_\ell |$$|Sℓ| is the number of (weakly) connected induced subgraphs of G on at most $$\ell $$ℓ vertices, $$\Delta $$Δ is the maximum degree of any vertex and $$\omega $$ω is the exponent of matrix multiplication. We compare the algorithm complexity both theoretically and experimentally with most of the existing algorithms for the same task. These comparisons show that the algorithm described here is the best general purpose algorithm for the class of graphs where $$(\ell ^{\omega -1}\Delta ^{-1}+1) |S_\ell |\le |\text {Cycle}_\ell |$$(ℓω-1Δ-1+1)|Sℓ|≤|Cycleℓ|, with $$|\text {Cycle}_\ell |$$|Cycleℓ| the total number of simple cycles of length at most $$\ell $$ℓ, including backtracks and self-loops. On Erdős–Rényi random graphs, we find empirically that this happens when the edge probability is larger than circa 4 / N. In addition, we show that some real-world networks also belong to this class. Finally, the algorithm permits the enumeration of simple cycles and simple paths on networks where vertices are labeled from an alphabet on n letters with an asymptotic running time of $$O\left( N+M+\big (n^\ell \ell ^\omega +\ell \Delta \big ) |S_\ell |\right) $$ON+M+(nℓℓω+ℓΔ)|Sℓ|. A Matlab implementation of the algorithm proposed here is available for download.

[1]  Ciro Cattuto,et al.  What's in a crowd? Analysis of face-to-face behavioral networks , 2010, Journal of theoretical biology.

[2]  Eric T. Bax Algorithms to Count Paths and Cycles , 1994, Inf. Process. Lett..

[3]  Berthe Y. Choueiry,et al.  An Algorithm for Generating All Connected Subgraphs with k Vertices of a Graph , 2013 .

[4]  Jaroslav Nesetril,et al.  Sparsity - Graphs, Structures, and Algorithms , 2012, Algorithms and combinatorics.

[5]  Michael R. Fellows,et al.  Parameterized Complexity , 1998 .

[6]  Michael Clausen,et al.  Algebraic complexity theory , 1997, Grundlehren der mathematischen Wissenschaften.

[7]  Blair D. Sullivan,et al.  Structural Sparsity of Complex Networks: Random Graph Models and Linear Algorithms , 2014, ArXiv.

[8]  Omid Amini,et al.  Counting Subgraphs via Homomorphisms , 2009, SIAM J. Discret. Math..

[9]  N. P. Khomenko,et al.  Identifying certain types of parts of a graph and computing their number , 1972 .

[10]  Leslie G. Valiant,et al.  The Complexity of Enumeration and Reliability Problems , 1979, SIAM J. Comput..

[11]  David Eppstein,et al.  The Polyhedral Approach to the Maximum Planar Subgraph Problem: New Chances for Related Problems , 1994, GD.

[12]  Donald B. Johnson,et al.  Finding All the Elementary Circuits of a Directed Graph , 1975, SIAM J. Comput..

[13]  Gordon G. Cash,et al.  The number of n-cycles in a graph , 2007, Appl. Math. Comput..

[14]  Russell Merris,et al.  Single-hook characters and hamiltonian circuits ∗ , 1983 .

[15]  David Avis,et al.  Reverse Search for Enumeration , 1996, Discret. Appl. Math..

[16]  René Schott,et al.  Complexity of counting cycles using zeons , 2011, Comput. Math. Appl..

[17]  Jörg Flum,et al.  The Parameterized Complexity of Counting Problems , 2004, SIAM J. Comput..

[18]  Albert,et al.  Emergence of scaling in random networks , 1999, Science.

[19]  Russell Merris Immanantal invariants of graphs , 2005 .

[20]  Russell Impagliazzo,et al.  On the Complexity of k-SAT , 2001, J. Comput. Syst. Sci..

[21]  Richard M. Karp,et al.  Dynamic programming meets the principle of inclusion and exclusion , 1982, Oper. Res. Lett..

[22]  N. P. Khomenko,et al.  The problem of isolating and counting , 1978 .

[23]  Frederic Dorn,et al.  Planar Subgraph Isomorphism Revisited , 2009, STACS.

[24]  Bader F. AlBdaiwi On the number of cycles in a graph , 2016, ArXiv.

[25]  Jérôme Kunegis,et al.  KONECT: the Koblenz network collection , 2013, WWW.

[26]  Richard J. Lipton,et al.  On the complexity of SAT , 1999, 40th Annual Symposium on Foundations of Computer Science (Cat. No.99CB37039).

[27]  Noga Alon,et al.  Finding and counting given length cycles , 1997, Algorithmica.

[28]  Leslie G. Valiant,et al.  The Complexity of Computing the Permanent , 1979, Theor. Comput. Sci..

[29]  Joel Franklin,et al.  A Finite-Difference Sieve to Count Paths and Cycles by Length , 1996, Inf. Process. Lett..

[30]  Narsingh Deo,et al.  On Algorithms for Enumerating All Circuits of a Graph , 1976, SIAM J. Comput..

[31]  Paul Rochet,et al.  Enumerating Simple Paths from Connected Induced Subgraphs , 2018, Graphs Comb..

[32]  Richard C. Wilson,et al.  Evaluating balance on social networks from their simple cycles , 2016, J. Complex Networks.

[33]  Roberto Grossi,et al.  Optimal Listing of Cycles and st-Paths in Undirected Graphs , 2012, SODA.

[34]  Khaled M. Elbassioni A Polynomial Delay Algorithm for Generating Connected Induced Subgraphs of a Given Cardinality , 2015, J. Graph Algorithms Appl..

[35]  Ryuhei Uehara,et al.  The Number of Connected Components in Graphs and Its Applications , 2007 .

[36]  Martin Grohe Descriptive and Parameterized Complexity , 1999, CSL.