Incremental Topological Ordering and Cycle Detection with Predictions

Samuel McCauley, Benjamin Moseley, Aidin Niaparast, Shikha Singh · DOI

Introduction

In the landscape of graph theory and its applications—ranging from compiler optimization to task scheduling and database management—maintaining a topological order is a fundamental requirement. A topological order is a linear arrangement of nodes in a Directed Acyclic Graph (DAG) such that for every directed edge $(u, v)$, node $u$ appears before node $v$.

While static topological sorting is a solved problem, the incremental setting presents a significant challenge: as edges are added one by one, how do we efficiently update the ordering or detect if a new edge creates a cycle? Traditionally, developers have faced a "theory-practice gap." Theoretical algorithms designed for optimal worst-case performance are often too complex for practical implementation, while simple greedy heuristics used in production can suffer from catastrophic performance degradation on difficult inputs. This paper bridges this gap by introducing the first "learning-augmented" data structures for incremental topological ordering.

The Framework: Algorithms with Predictions

The authors leverage the algorithms-with-predictions framework to "warm-start" dynamic data structures. The core idea is to use historical data or machine-learned models to predict the final structure of the graph. By using these predictions as a guide, the data structure can optimize its internal state to handle incoming updates more efficiently.

The Prediction Model

Rather than attempting to predict every specific edge—a task that is often fragile and prone to error—the authors utilize a coarse-grained prediction model. The model provides two summary statistics for each node: the predicted number of ancestor edges and the predicted number of descendant edges in the final graph. This high-level approach ensures the system remains robust to minor variations in the input data.

Proposed Algorithms

The research introduces two distinct approaches to integrate predictions into the ordering process:

  1. Learned DFS Ordering (LDFS): Designed for practical implementation, LDFS uses predictions to initialize "levels" for each node. When a new edge arrives that violates the current order, the algorithm performs a localized Depth-First Search (DFS) to reorder only the affected subset of the graph. This minimizes the computational overhead compared to global re-sorting.
  2. Ideal Learned Ordering: This is a more sophisticated theoretical construction. It decomposes the graph into smaller subproblems based on the provided predictions. Depending on the density or sparsity of these subproblems, the algorithm intelligently switches between state-of-the-art non-learned algorithms, such as the BK (Bender, Fineman, Gilbert, and Tarjan) or BFGT algorithms.

Theoretical Guarantees

A critical contribution of this work is the proof that the "Ideal" algorithm satisfies three key properties of learning-augmented design:

  • Consistency: The algorithm achieves optimal performance if the predictions are perfectly accurate.
  • Robustness: The algorithm's performance never falls below the best-known non-learned algorithms, even if the predictions are entirely incorrect.
  • Smoothness: The performance degrades gracefully as the error in the predictions increases, rather than failing abruptly.

Experimental Evaluation

The researchers evaluated the LDFS algorithm against several real-world temporal networks from the SNAP collection, including:

  • email-Eu-core: Communication patterns within a European research institution.
  • CollegeMsg: Private messaging data from a social network.
  • Math Overflow: A network of user interactions on the Stack Exchange platform.
  • Synthetic DAGs: Controlled environments used to test scalability.

Key Results

The empirical findings demonstrate that even simple predictions can yield massive performance gains:

  • Computational Efficiency: On the Math Overflow dataset, training the model on just 5% of the data led to a 36x reduction in the number of nodes and edges processed. Increasing the training set to 50% resulted in a 116x improvement over standard baselines.
  • Wall-Clock Runtime: In practical execution time, the LDFS algorithm was approximately 3x faster than the most efficient traditional heuristics.
  • Resilience to Noise: The authors conducted stress tests by introducing random noise into the predictions. Remarkably, even when the predictions contained 61% noise, the learned algorithm continued to outperform traditional non-learned baselines.

Conclusion and Future Work

This research demonstrates that "warm-starting" data structures with machine-learned predictions is a powerful technique for improving the efficiency of fundamental graph operations. While the LDFS algorithm provides an immediate practical benefit, the "Ideal Learned Ordering" establishes a rigorous theoretical foundation for future developments.

Future research directions include extending this framework to fully dynamic graphs (supporting both edge insertions and deletions) and applying similar learning-augmented techniques to other core problems such as dynamic shortest paths or reachability maintenance.

Summary updated

BibTeX
@inproceedings{mccauley2024incremental,
  author = {Samuel McCauley and Benjamin Moseley and Aidin Niaparast and Shikha Singh},
  title = {{Incremental Topological Ordering and Cycle Detection with Predictions}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=wea7nsJdMc},
}
Figure