Data Structures & AlgorithmsHardICPC regional · shortest paths

Problem: What is the time complexity of Johnson's all-pairs shortest path algorithm on a sparse graph with V vertices and E edges?

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

Correct answer: B. O(V E log V)

Bellman-Ford once plus V runs of Dijkstra with a heap gives O(VE + V E log V), which is O(V E log V) for sparse graphs.

More Coding Interview Problems questions

Exams that ask this topic