A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/dsa/time-and-space-complexity-of-floyd-warshall-algorithm/ below:

Time and Space Complexity of Floyd Warshall Algorithm

Time and Space Complexity of Floyd Warshall Algorithm

Last Updated : 23 Jul, 2025

The Floyd Warshall Algorithm has a time complexity of O(V3) and a space complexity of O(V2), where V represents the number of vertices in the graph. This algorithm computes the shortest paths between all pairs of vertices in a weighted graph. The time complexity arises from the triple nested loops used to update the shortest path matrix, while the space complexity is determined by the need to store the distances between all pairs of vertices in a 2D array.

Aspect Complexity Time Complexity O(V3) Space Complexity O(V2)

Let's explore the detailed time and space complexity of the Floyd Warshall Algorithm:

Time Complexity of Floyd Warshall Algorithm:

Best Case: O(V3)

Average Case: O(V3)

Worst Case: O(V3)

Auxiliary Space Complexity of Floyd Warshall Algorithm:

The auxiliary space complexity of the Floyd-Warshall algorithm is O(V2), where V is the number of vertices in the graph. To create a 2-D matrix in order to store the shortest distance for each pair of nodes.

Distance Matrix: Utilizes a 2D array to store shortest distances between all pairs of vertices.

Additional Variables: May require supplementary variables for iteration and calculation.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4