The Floyd-Warshall all-pairs shortest paths algorithm for disconnected and very sparse graphs

被引:11
作者
Toroslu, Ismail H. [1 ]
机构
[1] METU, Dept Comp Engn, Ankara, Turkiye
关键词
all-pairs shortest path problem; Dijkstra's algorithm; Floyd-Warshall algorithm; Johnson's algorithm; sparse graphs;
D O I
10.1002/spe.3188
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
The Floyd-Warshall algorithm is the most popular algorithm for determining the shortest paths between all vertex pairs in a graph. It is a very simple and an elegant algorithm. However, for graphs without any negative weighted edges, using Dijkstra's shortest path algorithm for every vertex as a source vertex to produce all-pairs shortest paths works significantly better than the Floyd-Warshall algorithm, especially for large graphs. Furthermore, for graphs with negative weighted edges, with no negative cycle, in general Johnson's algorithm also performs better than the Floyd-Warshall algorithm for large graphs. Johnson's algorithm first transforms the graph into a non-negative one by using the Bellman-Ford algorithm, then applies the Dijkstra's algorithm to the transformed graph. Thus, mainly, the Floyd-Warshall algorithm is quite inefficient, especially for large graphs. In this paper, we show a simple improvement on the Floyd-Warshall algorithm that will increases its efficiency, especially for very sparse graphs (i.e., the number of its edges is less than the number of its vertices), so it can be used instead of more complicated alternatives. We also show that our approach is also very effective for denser disconnected graphs. Since the new algorithm modifies the original Floyd-Warshall algorithm, it is mainly aimed for directed graphs without negative cycles. Most programmers prefer to implement the Floyd-Warshall algorithm over more complicated but more efficient alternatives for solving all-pairs shortest path problems. In this work, we show that without the addition of any complicated data structures, the performance of the Floyd-Warshall algorithm can be improved very easily. Our practical approach works even better than its alternatives for large sparse graphs.
引用
收藏
页码:1287 / 1303
页数:17
相关论文
共 16 条
[1]  
Bellman Richard., 1958, Quarterly of Applied Mathematics, V16, P87, DOI DOI 10.1090/QAM/102435
[2]   Modifications of the Floyd-Warshall algorithm with nearly quadratic expected-time [J].
Brodnik, Andrej ;
Grgurovic, Marko ;
Pozar, Rok .
ARS MATHEMATICA CONTEMPORANEA, 2022, 22 (01)
[3]   Solving all-pairs shortest path by single-source computations: Theory and practice [J].
Brodnik, Andrej ;
Grgurovic, Marko .
DISCRETE APPLIED MATHEMATICS, 2017, 231 :119-130
[4]  
Cormen ThomasH., 2009, Introduction to algorithms, V3, P631
[5]   A new approach to dynamic all pairs shortest paths [J].
Demetrescu, C ;
Italiano, GF .
JOURNAL OF THE ACM, 2004, 51 (06) :968-992
[6]   Experimental Analysis of Dynamic All Pairs Shortest Path Algorithms [J].
Demetrescu, Camil ;
Italiano, Giuseppe F. .
ACM TRANSACTIONS ON ALGORITHMS, 2006, 2 (04)
[7]  
Dijkstra E.W., 1959, NUMER MATH, V1, pS. 269, DOI [10.1007/BF01386390, DOI 10.1007/BF01386390]
[8]   Random Graph Modeling: A Survey of the Concepts [J].
Drobyshevskiy, Mikhail ;
Turdakov, Denis .
ACM COMPUTING SURVEYS, 2020, 52 (06)
[9]  
Erdős P, 2022, PUBL MATH DEBRECEN, V6, P290, DOI [10.5486/pmd.1959.6.3-4.12, DOI 10.5486/PMD.1959.6.3-4.12, 10.5486/PMD.1959.6.3-4.12]
[10]   ALGORITHM-97 - SHORTEST PATH [J].
FLOYD, RW .
COMMUNICATIONS OF THE ACM, 1962, 5 (06) :345-345