Data Structures & AlgorithmsModerateICPC regional · shortest path

Problem: Which statement about the Floyd-Warshall algorithm's memory usage for V vertices is correct?

  1. A. O(V^3) because each k needs a new matrix
  2. B. O(E) only
  3. C. O(1) because the answer is printed
  4. D. O(V^2), one matrix updated in place

Correct answer: D. O(V^2), one matrix updated in place

The in-place update uses a single V x V matrix, so the memory is O(V^2).

More Coding Interview Problems questions

Exams that ask this topic