We consider the problem of counting 4-cycles ($C_4$) in an undirected graph $G$ of $n$ vertices and $m$ edges (in bipartite graphs, 4-cycles are also often referred to as $\textit{butterflies}$). There have been a number of previous algorithms for this problem based on sorting the graph by degree and using randomized hash tables. These are appealing in theory due to compact storage and fast access on average. But, the performance of hash tables can degrade unpredictably and are also vulnerable to adversarial input. We develop a new simpler algorithm for counting $C_4$ requiring $O(m\bar\delta(G))$ time and $O(n)$ space, where $\bar \delta(G) \leq O(\sqrt{m})$ is the $\textit{average degeneracy}$ parameter introduced by Burkhardt, Faber & Harris (2020). It has several practical improvements over previous algorithms; for example, it is fully deterministic, does not require any sorting of the input graph, and uses only addition and array access in its inner loops. To the best of our knowledge, all previous efficient algorithms for $C_4$ counting have required $\Omega(m)$ space in addition to storing the input graph. 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\times$ -- $7\times$ faster on average compared to popular hash table implementations.
翻译:我们考虑在具有n个顶点和m条边的无向图G中计算4-环($C_4$)的问题(在二部图中,4-环通常也被称为蝴蝶)。已有多种基于图按度排序和使用随机哈希表的算法。这些算法在理论上因存储紧凑和平均访问速度快而具有吸引力。然而,哈希表的性能可能不可预测地退化,且容易受到对抗性输入的影响。我们开发了一种新的更简单的计算$C_4$的算法,所需时间为$O(m\bar\delta(G))$,空间为$O(n)$,其中$\bar \delta(G) \leq O(\sqrt{m})$是由Burkhardt、Faber和Harris(2020)引入的平均退化度参数。与先前算法相比,该算法具有多项实际改进;例如,它是完全确定性的,不需要对输入图进行任何排序,且其内循环仅使用加法和数组访问。据我们所知,所有先前的$C_4$计数高效算法在存储输入图之外都需要$\Omega(m)$的空间。我们的算法非常简单,易于调整以计算每个顶点和边相关的4-环。实验测试表明,与流行的哈希表实现相比,我们的基于数组的方法平均速度快4至7倍。