Simple and efficient four-cycle counting on sparse graphs
Abstract
We consider the problem of counting 4-cycles (C4) in an undirected graph G of n vertices and m edges (in bipartite graphs, 4-cycles are also often referred to as butterflies). Most recently, Wang et al. (2019, 2022) developed algorithms for this problem based on hash tables and sorting the graph by degree. Their algorithm takes O(mδ) expected time and O(m) space, where δ ≤ O(m) is the average degeneracy parameter introduced by Burkhardt, Faber \& Harris (2020). We develop a streamlined version of this algorithm requiring O(mδ) time and precisely n words of space. It has several practical improvements and optimizations; for example, it is fully deterministic, does not require any auxiliary storage or sorting of the input graph, and uses only addition and array access in its inner loops. Our algorithm is very simple and easily adapted to count 4-cycles incident to each vertex and edge. Empirical tests demonstrate that our array-based approach is 4× -- 7× faster on average compared to popular hash table implementations.
Turn this paper into a lesson
ArcXiv compiles a structured reading guide from this paper's metadata: plain-English importance, contributions, prerequisite concepts, which sections to read first, flashcards, and a quiz. Grounded in the abstract, never invented.