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)?
- A. Floyd-Warshall with cubic cost
- B. Kruskal's algorithm
- C. Gale-Shapley
- 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
- Problem: What is the time complexity of Kadane's algorithm extended to 2D (maximum-sum submatrix) with an n x n matrix?
- Problem: A hash table uses chaining, and every insertion first scans the key’s chain to make sure the key is not already present. What is…
- Problem: Which problem does the 'LCA by Euler tour and RMQ' reduce to?
- Problem: Which property does a 'matroid intersection' problem violate in general, making it harder than a single matroid?
- Problem: What is the time complexity of finding a minimum spanning tree in a complete graph with V vertices using Prim's algorithm and an…
- Problem: What does Fermat's little theorem let you compute efficiently?