Graph Theory37 sections · 1633 units
Open in Course

Time Complexity Analysis

(Why it's slower)

Each iteration processes all EE edges. You run n1n-1 iterations. Total: O(VE)O(VE). In dense graphs where EV2E \approx V^2, this becomes O(V3)O(V^3). Dijkstra with a binary heap runs in O((V+E)logV)O((V + E) \log V), which is faster when edges are non-negative. For sparse graphs where EVE \approx V, Dijkstra is O(VlogV)O(V \log V) while Bellman-Ford is O(V2)O(V^2).

Bellman-Ford trades speed for correctness with negative weights. Use it only when necessary. If all weights are non-negative, Dijkstra is always the better choice.

Space complexity is O(V)O(V) for the data structures used.