What is the time complexity of the Floyd-Warshall algorithm to calculate all…

2023

What is the time complexity of the Floyd-Warshall algorithm to calculate all the shortest paths of a pair in an n-vertex graph?

  1. A.

    O(n2logn)

  2. B.

    Θ(n2logn)

  3. C.

    Θ(n4)

  4. D.

    Θ(n3)

Attempted by 107 students.

Show answer & explanation

Correct answer: D

The Floyd – Warshall algorithm uses three nested loops to calculate all the shortest paths. Therefore, the time complexity is Θ(n ^ 3).

Explore the full course: Coding For Placement