Algorithm Engineering of SSSP with Negative Edge Weights

Alejandro Cassis, Andreas Karrenbauer, André Nusser, Paolo Luigi Rinaldi

Abstract

The Single-Source Shortest Path (SSSP) problem with negative edge weights has long faced a significant gap between theoretical complexity and practical performance. While recent breakthroughs have achieved near-linear time complexity in theory, these algorithms were widely considered too complex for efficient implementation. This paper presents the first high-performance C++ implementation of these recent theoretical advances, specifically the algorithm by Bringmann et al. (2023). Through targeted algorithm engineering—including optimized data structures, sampling parameters, and instance-based diameter bounds—we demonstrate a solver that outperforms the state-of-the-art Goldberg-Radzik algorithm by up to two orders of magnitude on challenging graph instances.

Introduction

The Single-Source Shortest Path (SSSP) problem is a fundamental building block in computer science, essential for applications ranging from financial modeling to network routing. When edge weights are non-negative, Dijkstra’s algorithm provides an efficient solution. However, the presence of negative edge weights (without negative cycles) significantly complicates the problem. For decades, the $O(mn)$ complexity of the Bellman-Ford algorithm remained the standard, which is prohibitively slow for massive modern datasets.

Theoretical breakthroughs in 2022 and 2023 finally achieved "near-linear" time complexity, roughly $O(m \log^3 n)$. Despite this milestone, these algorithms were initially viewed as purely theoretical due to high constant factors and the complexity of their subroutines. This work bridges the gap by applying algorithm engineering principles to transform these theoretical results into a robust, practical tool.

Algorithmic Framework

Our implementation is based on the framework proposed by Bringmann et al. (2023), which simplifies previous work by Bernstein et al. The core of the approach is a randomized graph decomposition strategy:

  1. Graph Decomposition (Decompose): The algorithm employs a randomized "ball-cutting" procedure. This process breaks the graph into smaller strongly connected components (SCCs) by removing a small subset of "cut edges." This decomposition allows the algorithm to isolate the challenges posed by negative weights.
  2. LazyDijkstra: Within these components, the algorithm uses a specialized subroutine that interleaves standard Dijkstra relaxations with Bellman-Ford-style updates. This hybrid approach efficiently handles the remaining negative edges within the SCCs.
  3. Recursive Scaling: The algorithm recursively processes the graph, gradually resolving the shortest path distances as it moves through the decomposition levels.

Engineering Optimizations

To move from a theoretical model to a competitive implementation, we introduced several critical optimizations:

  • Practical Data Structures: We replaced complex theoretical structures, such as Thorup’s priority queue, with a high-performance 4-heap. This significantly reduced constant-time overhead in the priority queue operations.
  • Sampling Parameter ($K$): We introduced a sampling parameter to limit the number of random vertices used during the decomposition phase. This modification speeds up the preprocessing step without sacrificing the quality of the graph decomposition.
  • Instance-Based Diameter Bounds: Theoretical bounds for the recursion depth ($\kappa$) are often overly pessimistic. By using the actual diameter of the graph instance to bound recursion, we improved scaling on random graphs by nearly an order of magnitude.

Experimental Evaluation

We evaluated our implementation (referred to as OUR) against the Goldberg-Radzik (GOR) algorithm, the previous practical state-of-the-art, across several benchmarks:

  • BAD and Augmented BAD Instances: These are pathological graphs designed to trigger the $O(mn)$ worst-case behavior in Bellman-Ford variants. Our augmented versions include random edges and permutations to prevent algorithms from exploiting simple structures like Directed Acyclic Graphs (DAGs).
  • Random Restricted Graphs: Synthetic graphs with controlled minimum cycle means to test the limits of relaxation-based solvers.
  • USA Road Networks: Real-world distance graphs from the 9th DIMACS challenge, modified with potential shifts to introduce negative weights.

Key Results

Our findings demonstrate that the engineered near-linear algorithm is not only viable but superior in many scenarios:

  • Significant Speedups: On "SHIFT-GOR" instances—specifically designed to be difficult for the GOR algorithm—our implementation was nearly 100 times faster.
  • Predictable Scaling: Unlike GOR, which exhibits high variance in performance depending on the graph structure, our algorithm showed stable, predictable scaling that aligns with the theoretical $O(m \log^3 n)$ complexity.
  • Real-World Competitiveness: On road networks, where GOR is highly optimized, our implementation remained within a factor of 5–7x of the baseline. This is a remarkably narrow gap for a first-of-its-kind implementation of a complex randomized algorithm.

Conclusion and Future Work

This work proves that the recent theoretical breakthroughs in SSSP are practically implementable and offer significant advantages in robustness and scaling. While our implementation is highly effective, two primary areas for future development remain. First, the algorithm currently relies on simple relaxation counting for negative cycle detection; integrating more sophisticated detection methods could broaden its utility. Second, the independent nature of the recursive calls on graph components makes the algorithm an ideal candidate for parallelization, which could further widen the performance gap over traditional sequential solvers.

Summary updated

BibTeX
@inproceedings{cassis2025algorithm,
  author = {Alejandro Cassis and Andreas Karrenbauer and André Nusser and Paolo Luigi Rinaldi},
  title = {{Algorithm Engineering of SSSP with Negative Edge Weights}},
  booktitle = {SEA},
  year = {2025},
  doi = {10.4230/lipics.sea.2025.10},
}
Figure