arXiv:2609.15848cs.DSSep 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2609.15848

Scalable Triangle Counting: The Threshold Algorithm

Asaf Etgar, Anna Gilbert, Quanquan C. Liu, Andrew McGregor

ABSTRACT

We study one-pass triangle counting on random-order edge streams. We present a remarkably simple algorithm—read edges from the stream until Q triangles are observed in the prefix, then output Q(m/S)3Q(m/S)^3 where S is the stopping length—and prove that, when the maximum number of triangles incident to any edge satisfies η≤T2/3\eta \leq T^{2/3}, this is a (1±ε)(1 \pm \varepsilon)-approximation of T with probability 1−δ1 - \delta using O(ε−2log⁡(1/δ)m/T1/3)O(\varepsilon^{-2} \log(1/\delta) m/T^{1/3}) memory. Crucially, the algorithm does not need any a priori estimate of T, in sharp contrast with state-of-the-art sampling-rate based algorithms [19, 30]. It also does not need a prescribed memory budget: the stopping rule self-selects the prefix length and can return an estimate before reading the entire stream.

The proof rests on a Schudy–Sviridenko concentration argument for an independent-edge-sampling estimator, coupled to the without-replacement prefix produced by the algorithm. On six real temporal streams, the algorithm’s stopping prefix follows the predicted cube-root scaling and achieves at most 6% error at a 10% prefix, without using T. At a fixed stored-edge budget, variance-reduced reservoir samplers are often more accurate, but only after reading the entire stream. On a separate, much larger, 1.8×1091.8 \times 10^9-edge graph, the threshold algorithm reads 0.46% of the stream and returns 3.8% error, while the strongest reservoir baselines do not finish a pass within the wall-clock cap.

PVLDB Reference Format:

Asaf Etgar, Anna Gilbert, Quanquan C. Liu, and Andrew McGregor. Scalable Triangle Counting: The Threshold Algorithm. PVLDB, 14(1): XXX-XXX, 2020.

doi:XX.XX/XXX.XX

PVLDB Artifact Availability:

The source code, data, and/or other artifacts have been made available at https://github.com/WildAlg/threshold-algorithm.

1 INTRODUCTION

Counting the number of triangles TT in a massive graph G=(V,E)G = (V, E) is one of the most-studied primitives in scalable graph data science [2,

Anna Gilbert

Yale University

New Haven, USA

anna.gilbert@yale.edu

Andrew McGregor

University of Massachusetts

Amherst, USA

amcgrego@umass.edu

6–9, 12, 13, 20, 22]. In the single-pass streaming model, an algorithm sees the edges of G one at a time and must output an estimate of T using memory much smaller than ∣E∣=m|E| = m. Sampling primitives are the standard design paradigm in this setting. There is also a long line of work on counting triangles via sublinear time algorithms that, potentially in addition to sampling, may make various queries to the graph [1, 3, 4, 11, 29].

Worst-case lower bounds make this problem challenging: even on random-order streams, any (1+ε)(1 + \varepsilon)-approximation requires Ω(ε−2m/T)\Omega(\varepsilon^{-2}m/\sqrt{T}) memory when T≤mT \leq \sqrt{m} [19]. State-of-the-art random-order algorithms [19, 30, 31] attain this bound up to log factors, and all utilize a sample-based approach: They set a sampling rate pp (or multiple rates) and sample edges as they arrive. Crucially, they are all TT-aware and require an aa priori constant-factor estimate of TT to set their sampling rate. This requirement is prohibitive on real-world streams: even two snapshots of the same network can differ in TT by an order of magnitude.

Another family of triangle counting algorithms are T-free and do not require an estimate on T [9, 14, 17, 21, 26, 27, 32]. These algorithms are provided with a specified memory budget M, and utilize reservoir or budget sampling to keep a variance-reducing set, typically alongside a running unbiased triangle count. While these families of algorithms do not assume a priori knowledge of T, both families suffer from scalability and adaptability issues. First, they require a full pass over the entire stream of edges. When graphs grow in orders of magnitude, even a single pass could be the runtime bottleneck for an algorithm, even if all other parameters are set optimally. Secondly, they rely on input parameters to guarantee accuracy; e.g., a sufficiently large memory budget.

This paper studies a remarkably simple alternative: An algorithm that returns a global estimate of T while only looking at a small prefix of the stream and without an initial estimate of T or a memory budget. In a random order stream, any prefix consists of a uniform sample of edges drawn without replacement. Consequently, rather than forcing a full pass over the stream, our algorithm halts when a prefix is large enough to serve as a signal for the entire graph. A major benefit of the algorithm is that said prefix is self-selected by the algorithm and does not need to be prescribed, while still guaranteeing a tight approximation of T. The algorithm is surprisingly simple to implement, and different implementations allow the user to adjust the space-time-accuracy tradeoff according to use case constraints.

This work is licensed under the Creative Commons BY-NC-ND 4.0 International License. Visit https://creativecommons.org/licenses/by-nc-nd/4.0/ to view a copy of this license. For any use beyond those covered by this license, obtain permission by emailing info@vldb.org. Copyright is held by the owner/author(s). Publication rights licensed to the VLDB Endowment.

Proceedings of the VLDB Endowment, Vol. 14, No. 1 ISSN 2150-8097. doi:XX.XX/XXX.XX

More formally, let G=(V,E)G = (V, E) be a simple graph with m=∣E∣m = |E| edges and TT triangles. For each edge ee, let τ(e)\tau(e) denote the number of triangles containing ee, and let

η:=max⁡e∈Eτ(e).\eta:=\max_{e\in E}\tau(e).

Throughout, we assume 0<ε≤1/20 < \varepsilon \leq 1/2 and 0<δ<1/100 < \delta < 1/10. We consider the stochastic process of drawing random edges from GG without replacement until some prescribed number QQ of triangles is observed (assuming Q≤TQ \leq T). Let SS be the random variable corresponding to the number of edges sampled by this process.

THEOREM 1.1. Assume η≤T2/3\eta \leq T^{2/3} and set Q=c0ε−6log⁡3(4/δ)Q = c_0 \varepsilon^{-6} \log^3(4/\delta) for a sufficiently large constant c0>0c_0 > 0. Then

T^:=Q(mS)3\widehat{T}:=Q\left(\frac{m}{S}\right)^{3}

is a (1±ε)(1 \pm \varepsilon) approximation of T with probability at least 1−δ1 - \delta. Furthermore, S=O(ε−2log⁡(1/δ) m/T1/3)S = O(\varepsilon^{-2} \log(1/\delta) \, m/T^{1/3}) with probability at least 1−δ1 - \delta.

The argument extends to arbitrary η\eta, but then the choice of QQ depends 1^1 on the unknown ratio η/T\eta/T.

Our algorithm uses O~(m/T1/3)\widetilde{O}(m/T^{1/3}) space. This is a factor ≈T1/6\approx T^{1/6} more than the space used by McGregor and Vorotnikova [19] (henceforth MV20) near both the optimal m/Tm/\sqrt{T} and the lower bound Ω(ε−2m/T)\Omega(\varepsilon^{-2}m/\sqrt{T}) of [19] (for T≤mT \leq \sqrt{m}). The experiments show that this premium buys a different operating point: the algorithm self-selects 1–6.6% prefixes with single-digit error on real temporal streams, reads only 0.46% of the 1.8×1091.8 \times 10^9-edge com-friendster stream with 3.8% error, and converts the main work into parallel static triangle counting on the stored prefix. Thus the tradeoff is qualitative rather than only asymptotic: instead of spending a full pass and a stale estimate of TT, the threshold rule allocates space from the observed stream and returns before the input is exhausted.

References (10)