Introduction
In the domain of graph mining, counting triangles—subgraphs consisting of three nodes where each is connected to the other two—is a fundamental task. It serves as a cornerstone for community detection, spam filtering, and calculating clustering coefficients. However, modern real-world graphs, such as social networks or web crawls, are often presented as "streams": continuous, high-velocity sequences of edges that are far too large to be stored in their entirety in main memory.
Existing streaming algorithms for triangle counting generally fall into two categories, each with significant drawbacks:
- Reservoir-based methods: These utilize a fixed memory budget. As the graph stream grows, the sampling ratio (the proportion of the graph being tracked) inevitably decreases, leading to a sharp decline in estimation accuracy over time.
- Bernoulli-based methods: These employ a fixed sampling probability. While this keeps the sampling ratio stable, the resulting memory usage is unpredictable and can easily exceed hardware limitations as the stream progresses.
This paper introduces BSR-TC, a novel streaming algorithm designed to maintain a stable sampling ratio while keeping memory usage controllable in a single-pass environment where the total graph size is unknown.
The BSR-TC Algorithm
The authors propose BSR-Sample (Bounded-Sampling-Ratio Sample) and its application to triangle counting, BSR-TC. The core innovation lies in its adaptive resizing mechanism.
Adaptive Resizing and Multi-Set Reservoirs
Unlike standard reservoirs with a fixed size, BSR-Sample begins with an initial memory budget ($M$). When the stream grows to a point where the sampling ratio hits a minimum threshold ($R$), the algorithm "freezes" the current sample into a pool and allocates a new block of memory to start a fresh reservoir. This multi-set approach allows the system to scale its memory footprint linearly with the graph's growth, ensuring that the sampling ratio remains bounded from below.
"First Counting, Then Sampling"
To maximize the utility of every incoming data point, BSR-TC employs a "first counting, then sampling" strategy. For every new edge $(u, v)$ arriving in the stream, the algorithm first checks if it completes any triangles with edges already present in the sample. Only after this estimation step is the edge considered for inclusion in the current sampling set.
Unbiased Estimation
The authors derive a specific probability formula ($p_{cuv}$) to weight discovered triangles. This ensures that the estimated count is mathematically unbiased, meaning its expected value is equal to the true number of triangles in the full graph. This mathematical rigor prevents the error rate from "drifting" as the stream continues.
Experimental Setup
The algorithm was evaluated using four large-scale datasets from the SNAP repository:
- Dblp: A collaboration network (317k nodes, 1M edges).
- Skitter: An internet topology graph (1.7M nodes, 11M edges).
- LiveJournal: A friendship network (4M nodes, 34M edges).
- Orkut: An online social network (3M nodes, 117M edges).
Key Results
BSR-TC demonstrates exceptional performance across all tested datasets. Notably, it achieved at least 99.8% accuracy for global triangle counting when the initial budget was at least 0.002% of the total graph and the threshold was set to 20%.
Superiority over Baselines
Compared to state-of-the-art algorithms such as ThinkDAcc, MASCOT, and WRS, BSR-TC provided up to 100x better accuracy for global triangle counts under certain conditions. On the Orkut dataset (117M edges), BSR-TC maintained a near-zero global error rate throughout the entire stream, whereas competing methods saw their error rates fluctuate or degrade significantly as the graph evolved.
As shown in the figure above, increasing the memory budget leads to a significant reduction in global error while increasing the number of discovered triangles, confirming the algorithm's effective use of available resources.
Discussion and Future Work
While BSR-TC offers a robust solution for "infinite" streams by adapting on the fly without requiring prior knowledge of the graph size, some challenges remain.
First, although the algorithm is adaptive, it still operates under the assumption of available physical RAM. Future work could explore "graceful degradation" strategies for scenarios where physical hardware limits are reached. Second, managing multiple sampling sets and calculating complex weights adds some computational overhead, though it remains efficient enough for single-pass streaming. Finally, while global accuracy is near-perfect, local (per-node) triangle counting accuracy is lower (approx. 60%), suggesting a need for further research into high-resolution local estimations.
Summary updated