Algorithmica | 2019

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

 
 
 

Abstract


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\xa0/\xa0N. 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.

Volume 81
Pages 2716-2737
DOI 10.1007/s00453-019-00552-1
Language English
Journal Algorithmica

Full Text