Open In App

Time and Space Complexity of Bellman–Ford Algorithm

The Bellman-Ford algorithm has a time complexity of O(V*E), where V is the number of vertices and E is the number of edges in the graph. In the worst-case scenario, the algorithm needs to iterate through all edges for each vertex, resulting in this time complexity. The space complexity of the Bellman-Ford algorithm is O(V), where V is the number of vertices in the graph. This space complexity is mainly due to storing the distances from the source vertex to all other vertices in the graph.

Operation Time Complexity Space Complexity
Initialization O(V) O(V)
Relaxation O(V*E) O(1)
Overall Complexity O(V*E) O(V)

Let’s explore the detailed time and space complexity of the Bellman–Ford Algorithm:



Time Complexity of Bellman-Ford Algorithm:

Best Case: O(E)

Average Case: O(V*E)



Worst Case: O(V*E)

Auxiliary Space Complexity of Bellman–Ford Algorithm:

The auxiliary space complexity of the Bellman-Ford algorithm is O(V), where V is the number of vertices in the graph, primarily due to the need to store distances from the source vertex to all other vertices.

Article Tags :