Data Structures & AlgorithmsHardICPC regional · shortest path

Problem: What is the worst-case complexity of the SPFA (queue-based Bellman-Ford) shortest path algorithm?

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

Correct answer: A. O(VE)

Each vertex can be re-enqueued up to V times with E relaxations per pass, giving O(VE) in the worst case.

More Coding Interview Problems questions

Exams that ask this topic