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


TOROSLU İ. H.

Software - Practice and Experience, cilt.53, sa.6, ss.1287-1303, 2023 (SCI-Expanded) identifier identifier

  • Yayın Türü: Makale / Tam Makale
  • Cilt numarası: 53 Sayı: 6
  • Basım Tarihi: 2023
  • Doi Numarası: 10.1002/spe.3188
  • Dergi Adı: Software - Practice and Experience
  • Derginin Tarandığı İndeksler: Science Citation Index Expanded (SCI-EXPANDED), Scopus, Aerospace Database, Applied Science & Technology Source, Communication Abstracts, Compendex, Computer & Applied Sciences, INSPEC, Metadex, zbMATH, Civil Engineering Abstracts
  • Sayfa Sayıları: ss.1287-1303
  • Anahtar Kelimeler: all-pairs shortest path problem, Dijkstra's algorithm, Floyd-Warshall algorithm, Johnson's algorithm, sparse graphs
  • Orta Doğu Teknik Üniversitesi Adresli: Evet

Özet

© 2023 John Wiley & Sons Ltd.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.