Manuscript Offprint
arXiv:2609.15848Scalable Triangle Counting: The Threshold Algorithm
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 where S is the stopping length—and prove that, when the maximum number of triangles incident to any edge satisfies , this is a -approximation of T with probability using 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, -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 in a massive graph is one of the most-studied primitives in scalable graph data science [2,
Anna Gilbert
Yale University
New Haven, USA
Andrew McGregor
University of Massachusetts
Amherst, USA
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 . 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 -approximation requires memory when [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 (or multiple rates) and sample edges as they arrive. Crucially, they are all -aware and require an priori constant-factor estimate of to set their sampling rate. This requirement is prohibitive on real-world streams: even two snapshots of the same network can differ in 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 be a simple graph with edges and triangles. For each edge , let denote the number of triangles containing , and let
Throughout, we assume and . We consider the stochastic process of drawing random edges from without replacement until some prescribed number of triangles is observed (assuming ). Let be the random variable corresponding to the number of edges sampled by this process.
THEOREM 1.1. Assume and set for a sufficiently large constant . Then
is a approximation of T with probability at least . Furthermore, with probability at least .
The argument extends to arbitrary , but then the choice of depends on the unknown ratio .
Our algorithm uses space. This is a factor more than the space used by McGregor and Vorotnikova [19] (henceforth MV20) near both the optimal and the lower bound of [19] (for ). 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 -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 , the threshold rule allocates space from the observed stream and returns before the input is exhausted.
-
Section 3–Section 4 prove Theorem 1.1 via Schudy–Sviridenko concentration on the independent-edge-sampling estimator, coupled to the without-replacement prefix produced by the algorithm. As a byproduct of our analysis, we improve the bound on the sampling probability p by polylogarithmic factors, thereby improving the analysis for DOULION [30] and the subsequent work on triangle sparsifiers [31].
-
Section 5 evaluates the algorithm on six real temporal streams and two large-scale graphs (by order of magnitude). The threshold Q acts as a smooth self-adapting knob: accuracy increases with Q and our Threshold algorithm reads only 0.46%–6.6% of the stream, with single-digit error. Against MV20 [19] and a broad set of T-free baselines, Threshold is within 0.08 absolute error of the best equal-space method. The main advantage of our algorithm is the early-stop feature: forced to stop at the Threshold prefix, native reservoir samplers undershoot the triangle count.
Algorithm 1 Threshold algorithm for random-order triangle counting.
Require: Stream length m; triangle threshold Q; random-order stream of edges of G.
1: ; adjacency list ; .
2: for each arriving edge do
3: ▷ triangles closed by inserting e
4: ; update A to include e.
5: if then break
6: .
7: return .
with error and need 97–98% of the stream to reach 5–10% error, while Threshold returns after reading a very small prefix, reading up to fewer edges on com-friendster, and its GBBS [10] implementation scales to a speedup on 64 cores.
2 THE THRESHOLD ALGORITHM
We now describe the algorithm that realizes the stochastic process analyzed in Theorem 1.1. The algorithm receives a random-order stream of m edges from a graph G and is given a single integer parameter Q, the triangle threshold. It keeps every arriving edge in memory and incrementally counts triangles closed by each new edge; once Q triangles have been observed it stops storing edges and returns its estimate.
The implementation maintains S as a hash set and A as hash-based adjacency lists; each edge insertion costs time, so the total running time is dominated by the cost of the triangle enumeration inside the prefix of length S. Memory usage is machine words for the stored edges plus for the adjacency structure.
2.1 Theoretical guarantees
Algorithm 1 is the algorithm to which Theorem 1.1 directly refers. We restate the guarantee in terms of the algorithm’s parameters.
THEOREM 2.1 (RESTATEMENT OF THEOREM 1.1). Assume and set for a sufficiently large constant . Let S be the stopping time of Algorithm 1. Then satisfies
and with probability at least .
Section 3 and Section 4 give the proof. In Section 3, we analyze sufficient conditions for tight concentration of the sampled number of triangles in the independent-edge sampling setup via the Schudy–Sviridenko inequality [24]. In Section 4, we analyze the algorithm’s stopping time S. Because the prefix of a random order stream behaves like a uniform sample without replacement of the edges, bounding S directly is challenging. To overcome this, we couple the prefix with two binomial random variables and which represent prefix lengths drawn at an over-sampling rate and an under sampling rate . Crucially, a random-length prefix behaves identically to analyzing independent edge sampling allowing us to utilize results from Section 3. By carefully selecting the
One can resolve this limitation by using a learning-augmented predictor to estimate this ratio from initial stream data. This method is studied in the companion paper [18], which uses prefix bucket profiles and deep neural networks to estimate triangle and 4-cycle counts on graph families in both random and arbitrary orders.
rates and the threshold Q, we are able to couple S with , and consequently guarantee both tight concentration of S and of the estimator . Finally, we prove Theorem 2.1 in the parameter-free form under the promise .
Practical setting of Q. The constant in Theorem 2.1 is non-explicit, so rather than fixing Q as a number we fix the space budget directly and let it induce Q. Given a target memory fraction , we run the loop of Algorithm 1 until exactly edges have been stored, then report , where is the number of triangles closed within the stored prefix. This is exactly Algorithm 1 run with the implicit threshold : because a uniform random prefix of fraction contains triangles, the realized threshold concentrates at . Sweeping the memory budget is therefore equivalent to sweeping Q, and—crucially—requires no knowledge of , since is a quantity the operator already controls. (Deployed the other way around, with a fixed Q and no budget, the stopping time instead self-adjusts to the data and attains the bound of Theorem 2.1 automatically.) In the implementation the target is reached by a geometric doubling schedule; on the dense real streams the process halts essentially at , while on sparse streams the realized can exceed the target before Q triangles accumulate, so we always report the realized .
Heavy-edge regime. When , Theorem 1.1 no longer applies in the parameter-free form, but the analysis of Section 3–Section 4 still gives a -approximation provided Q is set to absorb the factor . The ratio can be estimated from a small prefix using learned features of the stream; we focus the experiments below on the parameter-free regime and leave a full learning-augmented evaluation to companion work.
3 CONCENTRATION OF TRIANGLES VIA INDEPENDENT EDGE SAMPLING
Fix a sampling rate , and sample each edge independently with probability . For each edge , let be the indicator that is sampled. Define the triangle counting polynomial
where the sum is over all triangles in G. Then Y is the number of sampled triangles, and
is the natural unbiased estimator for . The goal of this section is to derive a sufficient condition on ensuring .
3.1 The Schudy-Sviridenko inequality
We use the following result by Schudy and Sviridenko [24, Theorem 1.4].
THEOREM 3.1 (SCHUDY-SVIRIDENKO). Let be a polynomial of degree and maximal variable power in independent moment-bounded random variables , all with the same moment-boundedness parameter . Let denote the maximum expected partial derivative of order and . Then there is an absolute constant such that, for every ,
3.2 Applying the concentration result to triangle counting
We wish to bound the parameters of Theorem 3.1 for the triangle counting polynomial . Since no edge can appear twice in a single triangle and each triangle is comprised of 3 edges, is multilinear of degree 3. That is, and . The random variables are Bernoulli, and therefore a uniform moment bound is . For we compute a bound on .
LEMMA 3.2. For the triangle-counting polynomial
the Schudy-Sviridenko parameters satisfy , , , and .
Proof. First,
For r = 1, differentiating with respect to an edge-variable gives
Here, the notation means counting over all triangles containing the edge . Taking expectations,
Therefore .
For , fix distinct edges . Then is nonzero if and only if and share a common triangle. Since the graph is simple, two edges share at most one triangle. Hence
for all pairs of edges e, h, and thus .
For , recall that is multilinear of degree 3 with coefficient 1 for all summands. Therefore the third mixed derivative is 1 if and only if the three differentiated edges form a triangle and 0 otherwise. Hence .
We proceed to apply Theorem 3.1 according to the bounds computed. Set and then
We set
where R is the constant from Theorem 3.1. In this notation, Theorem 3.1 states
Using the upper bounds on , we obtain the following lower bounds on :
Since , . Since we have . Moreover,
and therefore . Thus the inequality simplifies to
(1)
We arrive at the following sufficient condition for concentration of around T.
THEOREM 3.3. Let G be a simple graph with T triangles and
Sample each edge independently with probability p, let Y be the number of sampled triangles, and define . There is an absolute constant C > 0 such that if where
where . Then .
PROOF. A sufficient condition for Eq. (1) to be bounded above by is:
Take where is the constant from Theorem 3.1. Rearranging the three lower bounds on in (2) gives exactly the displayed minimum condition in (3).
4 STOPPING TIMES FOR EDGE SAMPLING WITHOUT REPLACEMENT
The goal of this section is to apply the independent sampling result from Section 3 to a sampling without replacement setting. Fix a uniformly random ordering of the edges of . For , let denote the set of the first edges in this ordering, and let denote the number of triangles contained in . We wish to analyze the concentration of the stopping time
for an appropriate choice of a threshold Q. Bounding S directly is difficult as edges in are not drawn independently. In order to utilize Theorem 3.3, we look for a sampling rate r with the following properties:
(1) The rate r is large enough to guarantee tight concentration around T as in Theorem 3.3.
(2) The threshold Q is a reliable indicator that we have processed an r-fraction of the stream, and not much more.
Then, instead of directly analyzing S, we couple S with two random variables , with two distinct sampling rates , . We think of as an over sampling rate, and as an under sampling rate. Crucially, taking a prefix of a random length behaves like independent edge sampling from E, allowing us to utilize Theorem 3.3. Our choice of a threshold Q will separate these two sampling rates, and imply strong concentration of S. We proceed to formalize this approach.
4.1 Coupling the Stopping Time
Let denote the critical value of from Theorem 3.3. Let
Define two sampling rates
Consider two random variables and .
LEMMA 4.1. For each , the random set has the same distribution as an independent -sample of the edge set .
PROOF. Fix and a subset of size . Then
which is exactly the probability that F is obtained by keeping each edge independently with probability .
Consequently, the number of triangles in has the same distribution as the random variable Y from Section 3 with sampling rate . Set . We show that the choice of Q separates the two sampling rates with probability at least . Denote by the probability space where each edge in E is sampled independently with probability .
LEMMA 4.2. and .
PROOF. Recall that Theorem 3.3 applies at any sample rate that is at least , and that . Then for by Theorem 3.3 with probability at least ,
which proves the first inequality. Similarly, for with probability at least ,
proving the second inequality.
Combined with Lemma 4.1, Lemma 4.2 transfers immediately to random prefixes.
LEMMA 4.3. and .
PROOF. By Lemma 4.1,
and a similar argument holds for .
We can now bound the stopping time S.
COROLLARY 4.4 (CONCENTRATION OF S).
PROOF. Recall that . By Lemma 4.3, with probability at least , and therefore . Similarly, . with probability at least By the union bound
Applying the standard multiplicative Chernoff bound to gives
and similarly
Taking the union bound over both gives
Plugging in the definition of gives
Alongside , the union bound implies the corollary.
4.2 Designing a Triangle Estimator
By Corollary 4.4, the number of edges one must process before seeing Q triangles is tightly concentrated around mr. We wish to use S as an estimator for the underlying sampling rate r. Since and , this motivates the following estimate of the number of triangles in G:
COROLLARY 4.5 (TRIANGLE ESTIMATION).
Proof. Since
By Corollary 4.4, with probability at least
So with probability at least
□
4.3 Proof of Main Theorem
PROOF OF THEOREM 1.1. Recall that
If , all three terms are and so
Hence, we set for sufficiently large . Since ,
and therefore
Consequently
Setting and , by Corollary 4.5
Reparameterizing by and gives the result.
5 EXPERIMENTAL EVALUATION
The experiments test the main promise of the paper: the threshold algorithm chooses a short prefix on its own and estimates T accurately by only looking at the prefix of the stream. With a fixed stored-edge budget, the best reservoir samplers are often more accurate because they produce an estimate after reading the entire stream; the threshold algorithm is the first early-stopping algorithm that achieves comparable approximations looking at only a subset of the stream. Our advantage is that the algorithm stops early, needs no estimate of T, and still returns a whole-graph estimate.
Experimental Setup. We use six temporal streams from SNAP [16], the Network Repository [23], and KONECT [15] (copresence-InVS15, reddit, sx-superuser, wiki-talk-temporal, ca-cit-HepPh (the KONECT co-citation network; m = 3,148,447), and sx-stackoverflow), plus com-orkut and com-friendster for large-scale analysis. We remove self-loops and duplicate edges. All accuracy experiments use uniformly random edge orders, matching Theorem 2.1; the true triangle count is used only for scoring. Algorithm 1 is implemented in GBBS [10] with ParlayLib [5]; ground-truth counts use Shun-Tangwongsan [28]. We re-implemented the remaining baselines: TRIEST [9], ThinkD [27], WRS [26], GREAT [32], and MASCOT [17]; DOULION [30], MV20 [19], and triangle sparsification [31]; wedge and colorful samplers [21, 25]; and related estimators [7, 13, 14, 22]. All use the same C++/GBBS setup so every method sees identical input, representation, timing, and error accounting. Unless stated otherwise, accuracy entries report , where ranges over independent random stream orders (every trial draws a fresh seeded permutation; no permutation is reused across operating
Table 1: Graphs used in the evaluation. The first six are real temporal streams; the last two are static graphs streamed in uniformly random order for scalability.
| Graph | vertices | edges | triangles |
|---|---|---|---|
| copresence-InVS15 | 219 | 16,725 | 713,002 |
| 35,776 | 124,330 | 406,391 | |
| sx-superuser | 192,409 | 714,570 | 1,543,161 |
| wiki-talk-temporal | 1,094,018 | 2,787,967 | 8,113,676 |
| ca-cit-HepPh | 28,093 | 3,148,447 | 195,758,685 |
| sx-stackoverflow | 2,584,164 | 28,183,518 | 114,206,974 |
| com-orkut | 3,072,441 | 117,185,083 | 627,584,181 |
| com-friendster | 65,608,366 | 1,806,067,135 | 4,173,724,142 |
points or across algorithms). We use: 30 random orders for fixed-prefix accuracy rows (including the err.@10% column); 10 per Q for self-sizing; 10 per operating point for MV20; 20 orders for matched-space and iso-accuracy rows; and 5 for stream-read. Experiments run on shared-cluster nodes with two 32-core Intel Xeon Gold 8562Y+ CPUs, one thread per core, and 1–4 TB of DDR5. The real streams and com-orkut use a 1 TB node; com-friendster uses 4 TB. We compile the GBBS/ParlayLib code with g++.
5.1 Self-Sizing and Accuracy
Table 2 gives selected operating points while Fig. 1 shows the full sweep. The result is that Q behaves as a smooth accuracy knob: increasing Q lowers error while increasing the self-selected prefix, and S/m matches predicted space usage (labeled “pred.”). The algorithm takes only the triangle threshold Q: it reads until the prefix contains Q triangles, stops at S edges, and returns . Since a random f-prefix contains about triangles, we expect . We choose the smallest swept Q with single-digit mean error, reading only 0.9–9.2% of each stream. The last column is a separate 10%-prefix run (30 random orders); for ca-cit-HepPh and sx-stackoverflow, this is much larger than the threshold 1.0% and 0.9% prefixes that were used by our algorithm.
Table 2: Self-sizing on real streams. Q is the target number of prefix triangles; all other entries are percentages. The final column is a separate fixed-10%-prefix check.
| Stream | Q | pred. | S/m | err. | err.@10% |
|---|---|---|---|---|---|
| copresence | 50 | 4.1 | 6.2 | 7.8 | 2.6 |
| 50 | 5.0 | 6.6 | 4.7 | 6.1 | |
| sx-superuser | 500 | 6.9 | 9.2 | 3.8 | 3.2 |
| wiki-talk | 100 | 2.3 | 3.3 | 4.8 | 1.5 |
| ca-cit-HepPh | 50 | 0.6 | 1.0 | 5.5 | 0.3 |
| sx-stackoverflow | 50 | 0.8 | 0.9 | 7.2 | 0.7 |
5.2 Comparison with State-of-the-Art
Fig. 2 compares against MV20 [19], the state-of-the-art random-order streaming algorithm with the best asymptotic bounds. MV20 is given the true value of T; our algorithm is not. Asymptotically

Figure 1: Sweep of Q values. Error decreases while the fraction of space usage increases as Q grows. The algorithm is given Q only, never T or a memory budget.
MV20 uses nearly the optimal amount of space; empirically, however, its realized footprint is governed by a T-dependent floor that is independent of the accuracy parameter : across our streams the (corrected) implementation stores 49–77% of all edges regardless of the requested budget (65% on com-orkut, 77% on sx-stackoverflow). Given that space, MV20 with the true T is accurate—often more accurate than the threshold algorithm at a matched nominal . However, it stores roughly an order of magnitude more edges than our self-selected prefix at comparable error. Moreover, a single MV20 run on the 1.8-billion-edge com-friendster did not complete within 10 hours at 16 cores, whereas the threshold algorithm finishes every operating point in seconds (Section 5.4). The threshold algorithm reaches the single-digit accuracy regime without a triangle-count estimate while reading and storing only a small prefix.

Figure 2: Accuracy vs. space usage for the threshold algorithm (red, swept over Q) and MV20 (blue, swept over and given T).
Table 3 merges the two fixed-space views. In each cell, the left value is the mean relative error when the baseline receives exactly the threshold-selected budget and no ; the right value is the smallest budget fraction that matches the best Threshold accuracy target. Thus the matched-space comparison is exact (1.0× the same stored-edge budget), and Threshold is within 0.08 absolute error of the best entry in every column. The same-accuracy side shows the complementary tradeoff: the variance-reduced reservoir samplers can match the target with less space on several streams, and Threshold uses at most the smallest matching space, but those methods still spend that memory after reading all m edges. Threshold spends more variance, and sometimes more prefix space, to avoid the whole-stream pass.
Books stress test. We also keep the controlled heavy-edge experiment under the neutral name books: each book has one spine edge shared by many triangular pages, and disjoint books are mixed with isolated triangles to sweep from to 10. At a 5% stored-edge budget, the experiment cleanly explains the theorem's heavy-edge condition. When , triangles are spread out and wedge sampling is best (0.007 error versus Threshold's 0.031 at ). Near the boundary the picture reverses: Threshold beats the best space-only baseline at (0.131 versus 0.245) and at (0.238 versus 0.366). Past the boundary all methods degrade. The point is not that the condition is cosmetic; it is that the transition is visible, and the threshold rule is competitive precisely at that transition.
5.3 Early Stopping: The Previously Missing Domain
We now investigate the effect of our key novelty on accuracy and space usage. Table 4 shows that the threshold algorithm returns an estimate after seeing only 0.46%-6.6% of the stream. Reservoir samplers, budget samplers, and related streaming estimators [7, 9, 13, 14, 17, 20–22, 25–27, 30–32] are also single-pass algorithms, but they must see all m edges before returning the estimate. This is the resource that matters when the input itself is the bottleneck: on com-friendster, the threshold algorithm reads fewer edges before returning an estimate.
We next deny the reservoir samplers their whole-stream pass. In Table 5, every method is forced to stop at the same S-edge prefix selected by the threshold rule and is given no T. The off-the-shelf estimators report only the graph they have seen, so their whole-graph estimate undershoots to error . The column is deliberately oracle-aided: a random prefix has about triangles, so it scales the prefix count by . Knowing that the selected prefix is meaningful would require the triangle-count scale, essentially the precise value of T, so this gives the reservoir samplers far more power than their native interface. Useful early stopping is not just storing a prefix; it is knowing how to extrapolate it without a triangle-count estimate.
Finally, Table 6 removes memory as the bottleneck and asks how much of the stream must be read before a whole-graph estimate is within 10% or 5% error. A native reservoir sampler, even with unlimited memory, must read 97–98% of the stream because a random f-prefix contains only about triangles. The threshold algorithm reaches comparable accuracy after a 1–7% prefix because it stops when it finds enough triangles and consequently extrapolates that number in its prefix to the entire graph.
5.4 Runtime Scalability
The measured streaming phase is consistent with the prefix cost. With 8 threads at a 5% prefix, the median streaming phase (prefix

Figure 3: Early stopping at the threshold prefix S. Reservoir samplers report the prefix graph and undershoot to error ; cubic extrapolation makes them comparable to the threshold algorithm, although the extrapolation still underperforms much of the time. The threshold algorithm is the method that provides this whole-graph estimate natively, with no T and no prescribed budget.
ingestion plus all checkpoint counts, excluding input parse and shuffle) takes 0.16 seconds on sx-stackoverflow, 0.53 seconds on com-orkut, and 10.8 seconds on the 1.8-billion-edge com-friendster — an effective rate of stream edges per second on the largest graph. The (corrected) MV20 implementation, which must read the whole stream and build its sketch, takes 200 seconds per trial on com-orkut at the same thread count. Early stopping helps twice: the algorithm skips the remaining edges, and after materializing the prefix it no longer has to maintain an online triangle estimator through sequential edge updates. The expensive work is instead triangle enumeration on a static prefix, so GBBS [10] parallelizes the edge-local neighbor-intersection counts and reduces the partial counts. The stream-order scan and the search over prefix lengths remain sequential across each graph; the dominant per-graph triangle count is what scales. Fig. 4 shows this parallel side: with the stream order fixed (so the work is identical at every thread count), the GBBS implementation reaches an speedup at 32 threads on com-orkut and at 32 threads on com-friendster (72% parallel efficiency); the larger graph scales better because its prefix exposes more parallel triangle-enumeration work per sequential byte.

Figure 4: Strong scaling (streaming phase, fixed stream order): on com-orkut and on the 1.8-billion-edge com-friendster at 32 threads.
Table 3: Matched-space and same-accuracy comparison. Each cell reports error at the threshold-selected budget . The Threshold row gives its matched-space error and the target error@space used for the second quantity. The columns are the streams common to both sweeps. Reservoir methods may win either half, but only after reading the whole stream; Threshold returns from the prefix. Bold marks the best value within each half of a column.
| Algorithm | sx-superuser | wiki-talk | cit-HepPh | copresence | |
|---|---|---|---|---|---|
| stored edges / target | 32,781 / 0.017@18% | 131,087 / 0.018@9% | 32,781 / 0.010@4% | 8,203 / 0.048@13% | 1,032 / 0.024@12% |
| Threshold (ours) | 0.065 / 18% | 0.039 / 9% | 0.056 / 4% | 0.094 / 13% | 0.095 / 12% |
| BuriolPODS [7] | 2.261 / >20% | 2.824 / >20% | 0.079 / >20% | 0.868 / >20% | 0.051 / >20% |
| ColorfulTC [21] | 0.051 / 20% | 0.023 / 10% | 0.018 / 5% | 0.046 / 15% | 0.058 / >20% |
| Doulion [30] | 0.073 / >20% | 0.028 / 15% | 0.074 / 5% | 0.074 / 20% | 0.059 / >20% |
| FURL [14] | 0.087 / 20% | 0.035 / 10% | 0.048 / 10% | 0.071 / 15% | 0.107 / >20% |
| GreatI [32] | 0.030 / 20% | 0.010 / 5% | 0.011 / 2% | 0.040 / 10% | 0.033 / 20% |
| GreatII [32] | 0.024 / 10% | 0.011 / 5% | 0.010 / 1% | 0.024 / 10% | 0.036 / 10% |
| GreatPlus [32] | 0.025 / 15% | 0.010 / 5% | 0.011 / 2% | 0.043 / 10% | 0.056 / 20% |
| MV20 [19] | 0.073 / >20% | 0.028 / 15% | 0.074 / 5% | 0.074 / 20% | 0.059 / >20% |
| Martingale [9] | 0.028 / 15% | 0.017 / 5% | 0.006 / 1% | 0.044 / 10% | 0.015 / 5% |
| MascotC [17] | 0.073 / >20% | 0.028 / 15% | 0.074 / 5% | 0.074 / 20% | 0.059 / >20% |
| MascotI [17] | 0.038 / >20% | 0.023 / 10% | 0.016 / 5% | 0.048 / 10% | 0.033 / 15% |
| NaiveScale (control) | 0.108 / >20% | 0.032 / 10% | 0.062 / 5% | 0.113 / 15% | 0.072 / 15% |
| ThinkDAcc [27] | 0.028 / 15% | 0.017 / 5% | 0.006 / 1% | 0.044 / 10% | 0.015 / 5% |
| ThinkDFast [27] | 0.028 / 15% | 0.017 / 5% | 0.005 / 1% | 0.044 / 10% | 0.015 / 5% |
| TriangleSparsifier [31] | 0.073 / >20% | 0.028 / 15% | 0.074 / 5% | 0.074 / 20% | 0.059 / >20% |
| TriestBase [9] | 0.091 / >20% | 0.052 / 15% | 0.068 / 5% | 0.083 / 20% | 0.051 / 15% |
| TriestImpr [9] | 0.028 / 15% | 0.017 / 5% | 0.006 / 1% | 0.044 / 10% | 0.015 / 5% |
| WRS [26] | 0.030 / 15% | 0.018 / 10% | 0.009 / 1% | 0.045 / 5% | 0.015 / 5% |
| WedgeSampling [25] | 0.053 / 15% | 0.066 / >20% | 0.007 / 1% | 0.031 / 5% | 0.015 / 1% |
Table 4: Early stopping. The threshold algorithm halts after edges; any reservoir/sampling baseline must see all edges. On com-friendster this is a 215× stream-read reduction.
| Stream | reads | |||
|---|---|---|---|---|
| copresence | 16,725 | 1,032 | 6.2% | 16× |
| reddit-hyperlink | 124,330 | 8,203 | 6.6% | 15× |
| sx-superuser | 714,570 | 32,781 | 4.6% | 22× |
| wiki-talk | 2,787,967 | 131,087 | 4.7% | 21× |
| cit-HepPh | 3,148,447 | 32,781 | 1.0% | 96× |
| sx-stackoverflow | 28,183,518 | 367,018 | 1.3% | 77× |
| com-orkut | 117,185,083 | 1,048,594 | 0.9% | 112× |
| com-friendster | 1,806,067,135 | 8,388,629 | 0.5% | 215× |
| any reservoir/sampling method | 100% | 1× |
6 CONCLUSION
The threshold algorithm reframes streaming triangle counting as a stopping problem rather than a budgeting problem: read until triangles appear in the prefix, then return . Under , this gives a approximation using space, without knowing or a memory budget in advance. Stopping is an algorithmic resource. While reservoir samplers remain strong when accuracy is measured after a full pass, they are inefficient when stream access is a scarce resource. The threshold algorithm self-selects the prefix, returns a whole-graph estimate after seeing only 0.46%–6.6% of the stream, and on a -edge graph reads 0.46% of the edges with 3.8% error. A small random prefix can be enough, especially when you know when to stop.
Table 5: Forced early stop at our self-selected prefix , with budget and no . Native samplers report the prefix graph and undershoot to error ; adding our cubic extrapolation (which requires precise knowledge of ) makes them comparable. The threshold algorithm provides the whole-graph estimate. Best of extrapolated sampler and Threshold is bold.
| Stream | samplers @ | Threshold (ours) | ||
|---|---|---|---|---|
| copresence | 6.2% | 1.00 | 0.083 | 0.095 |
| 6.6% | 1.00 | 0.087 | 0.094 | |
| sx-superuser | 4.6% | 1.00 | 0.075 | 0.065 |
| wiki-talk | 4.7% | 1.00 | 0.040 | 0.039 |
| cit-HepPh | 1.0% | 1.00 | 0.068 | 0.056 |
| stackoverflow | 1.3% | 1.00 | 0.037 | 0.075 |
| com-orkut | 0.9% | 1.00 | 0.055 | 0.024 |
| com-friendster | 0.46% | 1.00 | 0.043 | 0.038 |
Table 6: Stream read before a whole-graph estimate is within , with unlimited memory. Native reservoir samplers must read almost all edges because an -prefix contains about triangles; cubic extrapolation helps only after being handed the stopping fraction.
| Stream | Threshold reads (err) | Reservoir (native) | Reservoir | ||
|---|---|---|---|---|---|
| sx-superuser | 5% (0.065) | 97% | 98% | 4% | 6% |
| wiki-talk | 5% (0.039) | 97% | 98% | 2% | 4% |
| cit-HepPh | 1% (0.056) | 97% | 98% | 1% | 1% |
| 7% (0.094) | 97% | 98% | 5% | 11% | |
| copresence | 6% (0.095) | 97% | 98% | 2% | 7% |
REFERENCES
[1] Sepehr Assadi, Michael Kapralov, and Sanjeev Khanna. 2019. A Simple Sublinear-Time Algorithm for Counting Arbitrary Subgraphs via Edge Sampling. In Innovations in Theoretical Computer Science (ITCS). https://theory.epfl.ch/kapralov/papers/subgraphCountingITCS.pdf
[2] Ziv Bar-Yossef, Ravi Kumar, and D. Sivakumar. 2002. Reductions in Streaming Algorithms, with an Application to Counting Triangles in Graphs. In Proceedings of the Thirteenth Annual ACM-SIAM Symposium on Discrete Algorithms (SODA). 623–632. https://twiki.di.uniroma1.it/pub/Ing_algo/WebHome/triangles.pdf Preprint PDF (SODA'02).
[3] Suman K. Bera and C. Seshadhri. 2020. How to Count Triangles, without Seeing the Whole Graph. In Proceedings of the 26th ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (KDD). https://doi.org/10.1145/3394486.3403073
[4] Arijit Bishnu, Debarshi Chanda, and Gopinath Mishra. 2025. Arboricity and Random Edge Queries Matter for Triangle Counting using Sublinear Queries. arXiv preprint (2025). https://arxiv.org/pdf/2502.15379
[5] Guy E. Blelloch, Daniel Anderson, and Laxman Dhulipala. 2020. ParlayLib: A Toolkit for Parallel Algorithms on Shared-Memory Multicore Machines. In Proceedings of the 32nd ACM Symposium on Parallelism in Algorithms and Architectures (SPAA). ACM, Virtual Event, USA, 507–509. https://doi.org/10.1145/3350755.3400254
[6] Vladimir Braverman, Rafail Ostrovsky, and Dan Vilenchik. 2013. How Hard is Counting Triangles in the Streaming Model. In International Colloquium on Automata, Languages, and Programming (ICALP). https://web.cs.ucla.edu/~rafail/PUBLIC/148.pdf arXiv preprint (ICALP'13 version).
[7] Luciana S. Buriol, Gereon Frahling, Stefano Leonardi, Alberto Marchetti-Spaccamela, and Christian Sohler. 2006. Counting Triangles in Data Streams. In Proceedings of the Twenty-Fifth ACM SIGMOD-SIGACT-SIGART Symposium on Principles of Database Systems (PODS). 253–262. https://www.cs.umd.edu/~samir/498/triang.pdf PDF (conference version).
[8] Graham Cormode and Hossein Jowhari. 2014. A Second Look at Counting Triangles in Graph Streams. Theoretical Computer Science 552 (2014), 44–51. https://dimacs.rutgers.edu/~graham/pubs/papers/trianglestcs.pdf Preprint PDF (TCS 2014).
[9] Lorenzo De Stefani, Alessandro Epasto, Matteo Riondato, and Eli Upfal. 2016. TRIEST: Counting Local and Global Triangles in Fully-dynamic Streams with Fixed Memory Size. In Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (KDD). https://arxiv.org/pdf/1602.07424
[10] Laxman Dhulipala, Guy E. Blelloch, and Julian Shun. 2018. Theoretically Efficient Parallel Graph Algorithms Can Be Fast and Scalable. In SPAA.
[11] Talya Eden, Amit Levi, and Dana Ron. 2015. Approximately Counting Triangles in Sublinear Time (Full Version). Technical Report 046. Electronic Colloquium on Computational Complexity (ECCC). https://eccc.weizmann.ac.il/report/2015/046/download/
[12] Rajesh Jayaram and John Kallaugher. 2021. An Optimal Algorithm for Triangle Counting in the Stream. In APPROX/RANDOM (LIPics), Vol. 207. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 11:1–11:11.
[13] Madhav Jha, C. Seshadhri, and Ali Pinar. 2013. A Space Efficient Streaming Algorithm for Triangle Counting using the Birthday Paradox. In Proceedings of the 19th ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (KDD). 589–597. https://chbrown.github.io/kdd-2013-usb/kdd/p589.pdf Extended abstract PDF.
[14] Minsoo Jung, Sunmin Lee, Yongsub Lim, and U Kang. 2016. FURL: Fixed-memory and Uncertainty Reducing Local Triangle Counting for Graph Streams. arXiv preprint arXiv:1611.06615 (2016). https://arxiv.org/abs/1611.06615
[15] Jérôme Kunegis. 2013. KONECT: the Koblenz network collection. In Proceedings of the 22nd International Conference on World Wide Web (WWW Companion).
1343–1350. https://doi.org/10.1145/2487788.2488173
[16] Jure Leskovec and Andrej Krevl. 2014. SNAP Datasets: Stanford Large Network Dataset Collection. (2014).
[17] Yongsub Lim and U Kang. 2015. MASCOT: Memory-efficient and Accurate Sampling for Counting Local Triangles in Graph Streams. In Proceedings of the 21st ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (KDD). 685–694.
[18] Quanquan C. Liu, Aruzhan Amanbayeva, and Julian Shun. 2025. Scalable Streaming Subgraph Counting via Learned Prefix Bucket Profiles. In Proceedings of the VLDB Endowment (companion paper).
[19] Andrew McGregor and Sofya Vorotnikova. 2020. Triangle and four cycle counting in the data stream model. In ACM SIGMOD-SIGACT-SIGAI Symposium on Principles of Database Systems. 445–456.
[20] Andrew McGregor, Sofya Vorotnikova, and Hoa T. Vu. 2016. Better Algorithms for Counting Triangles in Data Streams. In Proceedings of the 35th ACM SIGMOD-SIGACT-SIGAI Symposium on Principles of Database Systems (PODS). 401–411. https://doi.org/10.1145/2902251.2902283
[21] Rasmus Pagh and Charalampos E. Tsourakakis. 2012. Colorful Triangle Counting and a MapReduce Implementation. Inform. Process. Lett. 112, 7 (2012), 277–281.
[22] Aduri Pavan, Kanat Tangwongsan, Srikanta Tirthapura, and Kun-Lung Wu. 2013. Counting and Sampling Triangles from a Graph Stream. Proceedings of the VLDB Endowment (PVLDB) 6, 14 (2013), 1870–1881. https://www.vldb.org/pvldb/vol6/p1870-aduri.pdf
[23] Ryan A. Rossi and Nesreen K. Ahmed. 2015. The Network Data Repository with Interactive Graph Analytics and Visualization. In AAAI. https://networkrepository.com
[24] Warren Schudy and Maxim Sviridenko. 2012. Concentration and Moment Inequalities for Polynomials of Independent Random Variables. In Proceedings of the Twenty-Third Annual ACM-SIAM Symposium on Discrete Algorithms (SODA). 437–446. https://doi.org/10.1137/1.9781611973099.37
[25] C. Seshadhri, Ali Pinar, and Tamara G. Kolda. 2013. Wedge Sampling for Computing Clustering Coefficients and Triangle Counts on Large Graphs. arXiv preprint (2013). https://arxiv.org/pdf/1309.3321
[26] Kijung Shin. 2017. WRS: Waiting Room Sampling for Accurate Triangle Counting in Real Graph Streams. In Proceedings of the IEEE International Conference on Data Mining (ICDM). 1087–1092. https://arxiv.org/abs/1709.03147
[27] Kijung Shin, Jisu Kim, Bryan Hooi, and Christos Faloutsos. 2018. Think Before You Discard: Accurate Triangle Counting in Graph Streams with Deletions. In Proceedings of the European Conference on Machine Learning and Knowledge Discovery in Databases (ECML/PKDD). 141–157. Extended version in ACM TKDD 14(2), 2020.
[28] Julian Shun and Kanat Tangwongsan. 2015. Multicore Triangle Computations Without Tuning. In Proceedings of the 31st IEEE International Conference on Data Engineering (ICDE). IEEE Computer Society, Seoul, South Korea, 149–160. https://doi.org/10.1109/ICDE.2015.7113280
[29] Jakub Tětek. 2022. Approximate Triangle Counting via Sampling and Fast Matrix Multiplication. In International Colloquium on Automata, Languages, and Programming (ICALP). https://d-nb.info/1366700031/34 Open-access PDF hosted by DNB.
[30] Charalampos E. Tsourakakis, U Kang, Gary L. Miller, and Christos Faloutsos. 2009. DOULION: Counting Triangles in Massive Graphs with a Coin. In Proceedings of the 15th ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (KDD). 837–846. https://doi.org/10.1145/1557019.1557111
[31] Charalampos E. Tsourakakis, Mihail N. Kolountzakis, and Gary L. Miller. 2011. Triangle Sparsifiers. Journal of Graph Algorithms and Applications 15, 6 (2011), 703–726.
[32] Siyue Wu, Dingming Wu, Sinhong Cheuk, Tsz Nam Chan, and Kezhong Lu. 2025. GREAT: Generalized Reservoir Sampling based Triangle Counting Estimation over Streaming Graphs. Proceedings of the VLDB Endowment (PVLDB) 18, 7 (2025), 2031–2043.