Abstract

AbstractThe 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.

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call

Disclaimer: All third-party content on this website/platform is and will remain the property of their respective owners and is provided on "as is" basis without any warranties, express or implied. Use of third-party content does not indicate any affiliation, sponsorship with or endorsement by them. Any references to third-party content is to identify the corresponding services and shall be considered fair use under The CopyrightLaw.