Data Structures & AlgorithmsHardICPC regional · Product Company SDE

Problem: What is the time complexity of the Floyd-Warshall algorithm for finding shortest paths between every pair of nodes in a graph with V vertices?

  1. A. O(V E log V)
  2. B. O(V^3)
  3. C. O(V^2)
  4. D. O(V log V)

Correct answer: B. O(V^3)

Floyd-Warshall tries every intermediate vertex k for every pair (i,j), giving three nested loops over V vertices: O(V^3).

More Coding Interview Problems questions

Exams that ask this topic