Finding All Bounded-Length Simple Cycles in a Directed Graph

Anshul Gupta, Toyotaro SuzumuraarXiv 2021

Introduction

Finding all simple cycles—paths that start and end at the same vertex without repeating any intermediate vertices—is a fundamental problem in graph theory with applications ranging from financial fraud detection to social network analysis. While classical algorithms like Johnson’s (1975) are theoretically optimal for finding all cycles in a graph, they become computationally prohibitive when applied to modern, massive datasets. In many practical scenarios, researchers are only interested in cycles up to a specific maximum length $k$ (e.g., detecting short circular paths in money laundering). This paper introduces LC_CYCLES, a deterministic algorithm specifically optimized for finding all simple cycles of length $\le k$.

The LC_CYCLES Algorithm

The LC_CYCLES algorithm builds upon the traditional Depth-First Search (DFS) and backtracking framework but introduces three critical optimizations designed to prune the search space effectively in length-constrained environments.

1. Feasible Neighborhood Pruning

Before initiating a search from a source vertex $s$, the algorithm performs a Breadth-First Search (BFS) to identify the "feasible neighborhood." This step identifies only those vertices reachable from $s$ within $k-1$ steps. By restricting the DFS to this specific subgraph, the algorithm avoids exploring vast regions of the graph that could not possibly complete a cycle within the length constraint.

2. The Integer Locking Mechanism

In traditional cycle-finding algorithms, a vertex is typically marked as either "blocked" or "unblocked" to prevent redundant explorations. LC_CYCLES replaces this binary state with a novel Integer Lock, denoted as Lock(v). This value represents the maximum path length from the start vertex $s$ that could still potentially form a cycle through $v$.

If the DFS reaches a vertex $v$ with a current path length that exceeds its Lock value, the search is immediately pruned. This mechanism allows the algorithm to reuse information from previous failed searches: if a path of length $L$ failed to find a cycle, any subsequent path reaching $v$ with a length $\ge L$ is also guaranteed to fail, thus saving significant computation time.

3. Vertex Ordering

The authors observed that the order in which vertices are processed as potential cycle sources significantly impacts performance. By preprocessing the graph and sorting vertices by their degree (the number of connections), the algorithm handles denser regions more effectively. This heuristic ensures that the most complex subgraphs are processed in a manner that minimizes redundant work for subsequent, sparser sections of the graph.

Experimental Evaluation

The algorithm was evaluated using several large-scale directed graphs from the Stanford Network Analysis Project (SNAP), including social networks (soc-pokec), web graphs (web-Google), and product relationship graphs (amazon0505). These datasets range from 26,000 to 1.79 million vertices and up to 30 million edges.

Key Performance Metrics

  • Scalability: On the soc-pokec social network, LC_CYCLES successfully identified over 611 billion cycles of length $\le 6$.
  • Efficiency: For $k=4$, the algorithm processed most large-scale graphs within seconds or minutes on a single CPU. Interestingly, the ratio of execution time to the number of cycles found decreased as $k$ increased, indicating that the algorithm's pruning becomes relatively more powerful as the search space expands.
  • Impact of Sorting: The vertex ordering heuristic proved vital. For the wiki-topcats graph at $k=5$, sorting vertices by degree reduced the total runtime from over 28 hours to just under 5 hours.

Discussion and Insights

A significant advantage of LC_CYCLES is its inherent parallelism. The outer loop of the algorithm iterates through each vertex as a potential cycle start independently. This "embarrassingly parallel" structure makes it highly suitable for modern multi-core and distributed computing environments.

However, the algorithm does face limitations in extremely skewed "scale-free" networks. In graphs with highly non-uniform degree distributions, the $d^k$ complexity factor (where $d$ is the average degree) can lead to performance bottlenecks for larger values of $k$. Additionally, the recursive nature of DFS can occasionally lead to poor memory locality on graphs that exceed the system's cache capacity.

Conclusion

LC_CYCLES provides a robust, deterministic solution for the bounded-length simple cycle problem. By combining distance-aware pruning with a novel integer locking mechanism, it enables the analysis of cycles in massive real-world networks that were previously computationally inaccessible. Future work will focus on developing tighter theoretical bounds for skewed graphs and implementing fully distributed versions of the algorithm.

Summary updated

BibTeX
@misc{gupta2021finding,
  author = {Anshul Gupta and Toyotaro Suzumura},
  title = {{Finding All Bounded-Length Simple Cycles in a Directed Graph}},
  year = {2021},
  eprint = {2105.10094},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2105.10094},
}
Figure