Question:medium

What is the time complexity of the Bellman-Ford single-source shortest path algorithm on a completely connected weighted graph of $n$ vertices?

Show Hint

Bellman-Ford runs in $O(VE)$ time, where $V$ is the number of vertices and $E$ is the number of edges.
Updated On: Jul 6, 2026
  • $O(n^2)$
  • $O(n^2 \log n)$
  • $O(n^3)$
  • $O(n^3 \log n)$
Show Solution

The Correct Option is C

Approach Solution - 1

Step 1: Bellman-Ford's well-known running time is \(O(V \cdot E)\), where \(V\) is the number of vertices and \(E\) the number of edges.
Step 2: For a complete graph on \(n\) vertices, \(V = n\) and \(E = O(n^2)\) since every pair of vertices is connected.
Step 3: Substituting gives \(O(V \cdot E) = O(n \times n^2) = O(n^3)\).
\[ \boxed{O(n^3)} \]
Was this answer helpful?
0
Show Solution

Approach Solution -2

We can also reason about this by placing Bellman-Ford relative to other shortest-path algorithms whose complexities are commonly known:

  1. \(O(n^2)\): This is closer to the complexity of computing shortest paths from a single source using a simple array-based Dijkstra on a dense graph, which does far less repeated work than Bellman-Ford's multiple full passes.
  2. \(O(n^2 \log n)\): This resembles heap-based Dijkstra's complexity on a sparse-ish graph. Bellman-Ford doesn't use a heap or any ordering structure, so borrowing this complexity class doesn't fit it.
  3. \(O(n^3)\): Bellman-Ford is known to be slower than Dijkstra precisely because it blindly repeats \(n-1\) rounds of relaxation instead of greedily picking the nearest vertex each time; on a dense/complete graph that repeated brute-force approach lands at \(O(n^3)\), a full order of \(n\) above Dijkstra's dense-graph cost.
  4. \(O(n^3 \log n)\): This would only apply if each of the \(O(n^3)\) relaxation steps itself needed logarithmic overhead, e.g. from a data structure lookup, which Bellman-Ford's plain array-based relaxation doesn't require.

Positioning Bellman-Ford as "Dijkstra's cost, but repeated \(n\) times over due to no greedy shortcut" lands on one specific class.

Therefore, the correct answer is \(O(n^3)\).

Was this answer helpful?
0