The Floyd-Warshall algorithm is a dynamic programming technique used to find the shortest paths between all pairs of vertices in a weighted graph. It works on both directed and undirected graphs and can handle graphs with negative weights, but it does not work with graphs that contain negative cycles. The algorithm iteratively updates a distance matrix , where represents the shortest distance from vertex to vertex . The core of the algorithm is encapsulated in the following formula:
for all vertices . This process is repeated for each vertex as an intermediate point, ultimately ensuring that the shortest paths between all pairs of vertices are found. The time complexity of the Floyd-Warshall algorithm is , where is the number of vertices in the graph, making it less efficient for very large graphs compared to other shortest-path algorithms.
Start your personalized study experience with acemate today. Sign up for free and find summaries and mock exams for your university.