Submitted:
12 February 2026
Posted:
12 February 2026
Read the latest preprint version here
Abstract
Keywords:
MSC: 05C69; 68Q25; 68Q17; 68Q15
1. Introduction
- 1.
- Triangle Enumeration: List all .
- 2.
- 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 |
|
- 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 the maximum-degree vertex participates in a triangle, then , where , yielding total time . In particular, for a complete graph , .
- 2.
- Failure Case (): If no triangle exists, then , where is the arboricity of G, yielding total time .
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
- 1.
- 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.
- 2.
- 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.
- 3.
- 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. Conclusion
Acknowledgments
References
- Alon, N.; Yuster, R.; Zwick, U. Finding and counting given length cycles. Algorithmica 1997, 17, 209–223. [CrossRef]
- Patrascu, M. Towards polynomial lower bounds for dynamic problems. In Proceedings of the Proceedings of the Forty-Second ACM Symposium on Theory of Computing, New York, NY, USA, 2010; STOC ’10, pp. 603–610. [CrossRef]
- Chiba, N.; Nishizeki, T. Arboricity and Subgraph Listing Algorithms. SIAM Journal on computing 1985, 14, 210–223. [CrossRef]
- Vega, F. Aegypti: Triangle-Free Solver. https://pypi.org/project/aegypti. Accessed November 21, 2025.
- Latapy, M. Main-memory triangle computations for very large (sparse (power-law)) graphs. Theoretical computer science 2008, 407, 458–473. [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. [CrossRef]
- Newman, M.E. The Structure and Function of Complex Networks. SIAM Review 2003, 45, 167–256. [CrossRef]
| Graph | n | m | Density | Triangles | Aegypti | NetworkX |
|---|---|---|---|---|---|---|
| Tree (no triangles) | 10,000 | 9,999 | 0.0002 | 0 | 4.7 ms | 1.87 s |
| Erdos–Rényi () | 5,000 | 25,000 | 0.002 | 142 | 11.5 ms | 2.04 s |
| Erdos–Rényi () | 2,000 | 40,000 | 0.020 | 1,082 | 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 | 1,903 | 49 ms | 5.91 s |
| Dense random () | 1,000 | 74,825 | 0.150 | 891,234 | 376 ms | 3.61 s |
| Complete | 100 | 4,950 | 1.0 | 161,700 | 9.6 ms | 72 ms |
| Complete | 1,000 | 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. |
© 2026 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/).