Data Structures & AlgorithmsHardICPC regional · graph counting

Problem: Which algorithm computes the number of shortest paths between all pairs in an unweighted graph in O(V * E)?

  1. A. Floyd-Warshall with cubic cost
  2. B. Kruskal's algorithm
  3. C. Gale-Shapley
  4. D. BFS from every vertex

Correct answer: D. BFS from every vertex

Running BFS from each source counts shortest paths with the standard layered counting, which is O(V * E).

More Coding Interview Problems questions

Exams that ask this topic