English

A general purpose algorithm for counting simple cycles and simple paths of any length

Data Structures and Algorithms 2019-09-12 v1 Discrete Mathematics Combinatorics

Abstract

We describe a general purpose algorithm for counting simple cycles and simple paths of any length \ell on a (weighted di)graph on NN vertices and MM edges, achieving a time complexity of O(N+M+(ω+Δ)S)O\left(N+M+\big(\ell^\omega+\ell\Delta\big) |S_\ell|\right). In this expression, S|S_\ell| is the number of (weakly) connected induced subgraphs of GG 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 (ω1Δ1+1)SCycle(\ell^{\omega-1}\Delta^{-1}+1) |S_\ell|\leq |\text{Cycle}_\ell|, with Cycle|\text{Cycle}_\ell| the total number of simple cycles of length at most \ell, including backtracks and self-loops. On Erd\H{o}s-R\'enyi random graphs, we find empirically that this happens when the edge probability is larger than circa 4/N4/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 nn letters with a time complexity of O(N+M+(nω+Δ)S)O\left(N+M+\big(n^\ell\ell^\omega+\ell\Delta\big) |S_\ell|\right). A Matlab implementation of the algorithm proposed here is available for download.

Keywords

Cite

@article{arxiv.1612.05531,
  title  = {A general purpose algorithm for counting simple cycles and simple paths of any length},
  author = {Pierre-Louis Giscard and Nils Kriege and Richard C. Wilson},
  journal= {arXiv preprint arXiv:1612.05531},
  year   = {2019}
}
R2 v1 2026-06-22T17:26:15.205Z