Modifications of the Floyd-Warshall algorithm with nearly quadratic expected-time

Andrej Brodnik, Marko Grgurovič, Rok Požar


The paper describes two relatively simple modifications of the well-known Floyd-Warshall algorithm for computing all-pairs shortest paths. A fundamental difference of both modifications in comparison to the Floyd-Warshall algorithm is that the relaxation is done in a smart way. We show that the expected-case time complexity of both algorithms is O(n2log2n) for the class of complete directed graphs on n vertices with arc weights selected independently at random from the uniform distribution on [0, 1]. Theoretically best known algorithms for this class of graphs are all based on Dijkstra’s algorithm and obtain a better expected-case bound. However, by conducting an empirical evaluation we prove that our algorithms are at least competitive in practice with best know algorithms and, moreover, outperform most of them. The reason for the practical efficiency of the presented algorithms is the absence of use of priority queue.


All-pairs shortest paths, Probabilistic analysis

Full Text:



ISSN: 1855-3974

Issues from Vol 6, No 1 onward are partially supported by the Slovenian Research Agency from the Call for co-financing of scientific periodical publications