StreakPeaked· Practice

ExamsGATETechnical

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

  1. Θ(n²)
  2. Θ(n² log n)
  3. Θ(n³)
  4. Θ(n³ log n)

Correct answer: Θ(n³)

Solution

The Bellman-Ford algorithm has a time complexity of Θ(n * m), where n is the number of vertices and m is the number of edges. In a complete graph, the number of edges m is Θ(n²), leading to a total time complexity of Θ(n³).

Related GATE Technical questions

⚔️ Practice GATE Technical free + battle 1v1 →