Skip to content

Report-and-Run: A Simple Optimal Algorithm for All-Pairs Shortest Paths in Sparse Graphs

Ken-ichi Kawarabayashi, Yu Kohara

cs.DS

Abstract

We present the Report-and-Run algorithm (R&R algorithm), a simple deterministic algorithm in the comparison-addition model that, given an nn-vertex, O(n)O(n)-edge directed graph with arbitrary real edge weights, either detects a negative-weight cycle or solves the All-Pairs Shortest Paths (APSP) problem in O(n2)O(n^2) time. This matches the Ω(n2)Ω(n^2) output-size lower bound and gives the first optimal algorithm for sparse APSP in the comparison-addition model. We also introduce several variants of the R&R algorithm. First, for directed graphs with non-negative real weights and constant maximum in-degree and out-degree, we study computing the kk nearest vertices from every source. Under constant-time allocation of uninitialized arrays, lazy initialization yields deterministic O(nk)O(nk) time and O(n2)O(n^2) space, whereas randomized hash tables give O(nk)O(nk) expected time and O(nk)O(nk) worst-case space. Second, we present blocking and edge-caching heuristics that substantially reduce both comparisons and additions compared with Dijkstra's algorithm on sparse random graphs.

Create a lesson