Data Structures & AlgorithmsVery hardICPC regional · graph theory
Problem: Which statement about Floyd-Warshall on a graph with V = 400 vertices and no negative cycles is correct?
- A. About 1.6 * 10^5 relaxations, so it must be replaced by Dijkstra from every vertex
- B. It needs O(V!) time and is infeasible for V = 400
- C. It cannot handle negative weights at all, even without negative cycles
- D. About 6.4 * 10^7 relaxations, which runs comfortably in C++; negative edges are allowed
Correct answer: D. About 6.4 * 10^7 relaxations, which runs comfortably in C++; negative edges are allowed
The triple loop does V^3 = 6.4 * 10^7 relaxations for V = 400, which is fine in C++. Negative edges are allowed as long as there is no negative cycle.
More Coding Interview Problems questions
- Problem: Minimum number of taps needed to water a garden of length 5 is found from tap i covering [i - ri, i + ri]. Here n = 5 and r = [3…
- Problem: A stone game: piles [5, 3, 4, 5] lie in a row, and players alternately take a pile from either end. The first player wants to…
- Problem: Prim's algorithm starts at vertex 0 on the undirected weighted graph with edges 0-1 (6), 0-3 (2), 1-2 (3), 1-3 (8), 1-4 (5), 2-4…
- Problem: A directed graph on vertices 0–5 has arcs 0→1, 1→2, 2→0, 2→3, 3→4, 4→3, 4→5. Its strongly connected components are computed. How…
- Problem: The number of spanning trees of the complete graph K4 (4 labelled vertices, every pair joined by an edge) is what value?…
- Problem: A graph on vertices 0–6 has edges 0-1, 0-2, 1-3, 2-3, 3-4, 4-5, 5-6, 4-6. Count the bridges (edges whose removal increases the…