Submitted:
21 November 2025
Posted:
28 November 2025
You are already at the latest version
Abstract
Keywords:
MSC: 05C69; 68Q25; 68Q17; 68Q15
1. Introduction
- Triangle Enumeration: List all .
- Triangle Detection: Determine if and return a single witness if one exists.
2. The Aegypti Algorithm
2.1. Algorithm Specification
3. Theoretical Analysis
3.1. Correctness
| Algorithm 1 Adaptive Triangle Enumeration and Detection | |
1: function Aegypti(G, ) |
|
2: Sort V such that
|
▹ Process higher degree nodes first |
3: Let be the rank in sorted order. |
|
4:
|
|
5: if then
|
▹ Sparse Branch: Intersection Strategy |
6: Build adjacency map
|
|
7: for each (in sorted order) do
|
|
8: for each where do
|
|
9:
|
▹ Fast set intersection |
10: for each where do
|
|
11: yield
|
|
12: if thenreturn
|
|
13: end if
|
|
14: end for
|
|
15: end for
|
|
16: end for
|
|
17: else
|
▹ Dense Branch: Forward-Marking Strategy |
18: Initialize as empty sets for all v
|
|
19: for each (in sorted order) do
|
|
20:
|
|
21: for each do
|
▹ Identify forward neighbors |
22: if then
|
|
23:
|
|
24:
|
|
25:
|
|
26: end if
|
|
27: end for
|
|
28: for each pair distinct do
|
|
29: if then
|
|
30: yield
|
|
31: if thenreturn
|
|
32: end if
|
|
33: end if
|
|
34: end for
|
|
35: end for
|
|
36: end if
|
|
37: end function
|
- Sparse Branch: The outer loops iterate edges where . The triangle is found only when and . The intersection checks for w such that . Thus, t is yielded only when processing x, then y, finding z.
- Dense Branch: This branch utilizes a "forward neighbor" approach. The set effectively contains neighbors v that have not yet been processed as the "pivot". The condition ensures that for any edge , the edge is considered only when processing the vertex with the lower rank (the higher degree node). The triangle is checked only when the first of the three vertices (according to the loop order) is u.
3.2. Complexity Analysis: Enumeration
3.3. Complexity Analysis: Detection
- 1.
- Success Case (): If G contains triangles in high-core regions (e.g., social networks), .
- 2.
- Failure Case ():.
4. Experimental Evaluation
4.1. First-Triangle Detection Performance ()
- Complete graph : 30 μs
- Complete bipartite (triangle-free): 112 ms (Full scan required to prove emptiness)
- Typical real-world graphs with triangles: 0.1–0.8 ms
4.2. Detection Performance Analysis
- Real-World Graphs (0.1–0.8 ms): This result confirms the efficacy of the descending degree sort (). In heterogeneous networks (like Barabási–Albert or social graphs), triangles gather around hubs. By processing the highest-degree nodes first, the algorithm locates a triangle almost immediately, typically within the first few iterations of the outer loop.
- Dense Graphs (): With a detection time of 30 μs, the algorithm demonstrates that in the Dense Branch, the overhead of marking neighbors is negligible. The first checked pair in the first checked node’s neighborhood immediately yields a result.
- Worst-Case (): The bipartite graph requires a full traversal to return . The runtime of 112 ms for 1 million edges matches the full enumeration time, proving that the detection logic adds zero overhead when a full search is necessary.
5. Impact
6. Conclusions
Acknowledgments
References
- Alon, N.; Yuster, R.; Zwick, U. Finding and counting given length cycles. Algorithmica 1997, 17, 209–223. [Google Scholar] [CrossRef]
- Patrascu, M. Towards polynomial lower bounds for dynamic problems. In Proceedings of the Forty-Second ACM Symposium on Theory of Computing, New York, NY, USA, 5–8 June 2010; STOC’10. pp. 603–640. [Google Scholar] [CrossRef]
- Chiba, N.; Nishizeki, T. Arboricity and Subgraph Listing Algorithms. SIAM Journal on computing 1985, 14, 210–223. [Google Scholar] [CrossRef]
- Vega, F. Aegypti: Triangle-Free Solver. Available online: https://pypi.org/project/aegypti (accessed on 21 November 2025).
- Latapy, M. Main-memory triangle computations for very large (sparse (power-law)) graphs. Theoretical Computer Science 2008, 407, 458–473. [Google Scholar] [CrossRef]
- Milo, R.; Shen-Orr, S.; Itzkovitz, S.; Kashtan, N.; Chklovskii, D.; Alon, U. Network Motifs: Simple Building Blocks of Complex Networks. Science 2002, 298, 824–827. [Google Scholar] [CrossRef] [PubMed]
- Newman, M.E. The Structure and Function of Complex Networks. SIAM Review 2003, 45, 167–256. [Google Scholar] [CrossRef]
| Graph | n | m | Density | Triangles | Aegypti | NetworkX |
|---|---|---|---|---|---|---|
| Tree (no triangles) | 10,000 | 9999 | 0.0002 | 0 | 4.7 ms | 1.87 s |
| Erdos–Rényi () | 5000 | 25,000 | 0.002 | 142 | 11.5 ms | 2.04 s |
| Erdos–Rényi () | 2000 | 40,000 | 0.020 | 1082 | 18.9 ms | 412 ms |
| Zachary’s Karate Club | 34 | 78 | 0.139 | 45 | 0.31 ms | 1.12 ms |
| Barabási–Albert () | 10,000 | 39,988 | 0.0008 | 1903 | 49 ms | 5.91 s |
| Dense random () | 1000 | 74,825 | 0.150 | 891,234 | 376 ms | 3.61 s |
| Complete | 100 | 4950 | 1.0 | 161,700 | 9.6 ms | 72 ms |
| Complete | 1000 | 499,500 | 1.0 | ∼166M | 2.14 s | 18.4 s |
| Complete bipartite | 200 | 10,000 | 0.250 | 0 | 6.8 ms | 2.41 s |
| Complete bipartite | 2,000 | 1,000,000 | 0.500 | 0 | 112 ms | 41.3 s |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).
