NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

An Improved Algorithm for Incremental Cycle Detection and Topological Ordering in Sparse Graphs

Sayan Bhattacharya, Janardhan KulkarniSODA 2018

TL;DR

This paper introduces a new randomized algorithm for detecting cycles and maintaining topological order in directed graphs as edges are added incrementally. The algorithm achieves a total expected update time of $\tilde{O}(m^{4/3})$, which is a significant improvement over previous methods, especially for sparse graphs. This breakthrough breaks a long-standing theoretical barrier for this fundamental dynamic graph problem.

What Problem Does This Paper Address?

Imagine you have a directed graph, and you're adding edges one by one. After each edge addition, you need to know two things:

  1. Does the graph now contain a cycle? If it does, you can stop.
  2. If it's still acyclic, what's a valid topological ordering of its nodes? A topological ordering is a linear ordering of nodes such that for every directed edge from node A to node B, A comes before B in the ordering.

This is the problem of incremental cycle detection and topological ordering. The challenge is to design an algorithm that can efficiently handle these updates over a sequence of edge insertions, minimizing the total time spent across all updates. Previous algorithms had bounds that were too slow for sparse graphs (where the number of edges $m$ is much smaller than the square of the number of nodes $n$).

Methods

The authors present a randomized algorithm that cleverly combines two existing techniques:

  1. Bernstein and Chechik's [BC18] framework: This approach partitions the graph's nodes into subsets based on sampled ancestors and descendants. This partition helps to localize cycle detection and manage updates.
  2. Haeupler et al.'s [HKMST12] balanced search: This technique is used to efficiently search for paths within the graph. The paper adapts this by performing simultaneous forward and backward searches from the endpoints of the newly added edge. This "balanced search" is key to their improvement.

The algorithm proceeds in four phases for each edge insertion:

  • Phase I: Update the induced subgraphs based on the node partition.
  • Phase II: Adjust the topological ordering to be consistent with the node partition.
  • Phase III: Use the balanced search (forward and backward) to check for cycles. This is the core of the improvement.
  • Phase IV: If no cycle is found, ensure the topological ordering remains valid.

Datasets

Not discussed in the paper. The paper focuses on theoretical algorithm design and analysis for general directed graphs.

Key Insights and Ideas

  • The power of dual searches: By performing simultaneous forward and backward searches from the endpoints of a new edge, the algorithm can detect a path (and thus a cycle) much more efficiently than a single-direction search. This is because the searches "meet in the middle," significantly reducing the search space.
  • T-relatedness as a proxy for cycles: The concept of "$\tau$-related pairs" (nodes that are "close" in terms of ancestry/descendancy within a certain bound $\tau$) is used as a relaxation of being part of a cycle. If a pair is not $\tau$-related, they cannot be in a cycle together. This helps bound the number of potential cycle-forming paths.
  • Breaking the $\Omega(n\sqrt{m})$ barrier for local algorithms: The paper achieves a result that is better than a known lower bound for a specific class of "local" algorithms, demonstrating a significant theoretical advance.

Key Results

The paper's main contribution is a randomized algorithm for incremental cycle detection and topological ordering with an expected total update time of $\tilde{O}(m^{4/3})$. This is a significant improvement over previous bounds, particularly for sparse graphs ($m = o(n^{3/2})$).

  • Improved total update time: $\tilde{O}(m^{4/3})$ compared to previous $\tilde{O}(m \cdot \min(m^{1/2}, n^{2/3}))$ and $\tilde{O}(m\sqrt{n})$.
  • Breaks theoretical barriers: For sparse graphs where $m = o(n^{6/5})$, the algorithm achieves a total update time of $\tilde{O}(n\sqrt{m})$, which is better than the $\Omega(n\sqrt{m})$ lower bound for local algorithms.
  • Specific performance gains:
    • For sparse graphs ($m = O(n)$), the bound becomes $\tilde{O}(n^{4/3})$.
  • When $m = o(n^{3/2})$, the new bound $\tilde{O}(m^{4/3})$ is better than the $\tilde{O}(m\sqrt{n})$ bound from [BC18].

Limitations and Future Work

  • Randomized Algorithm: The algorithm is randomized, meaning its performance is guaranteed in expectation. Deterministic versions might have worse bounds.
  • Sparse Graph Focus: While the algorithm improves upon previous results for sparse graphs, the performance for very dense graphs ($m = \Omega(n^{3/2})$) is still dominated by older algorithms with $\tilde{O}(n^2)$ total update time.
  • Future Work: The paper's techniques could potentially be applied to other dynamic graph problems. The authors also note that it's an open question whether a deterministic algorithm with a similar time complexity exists.

Summary updated

BibTeX
@inproceedings{bhattacharya2018improved,
  author = {Sayan Bhattacharya and Janardhan Kulkarni},
  title = {{An Improved Algorithm for Incremental Cycle Detection and Topological Ordering in Sparse Graphs}},
  booktitle = {SODA},
  year = {2018},
  url = {https://openreview.net/forum?id=Npyd8_woNx},
}
Figure