Data Structures & AlgorithmsHardICPC regional · shortest path
Problem: Which statement about the Bellman-Ford algorithm is correct when there is a negative cycle reachable from the source?
- A. The algorithm returns the correct distances
- B. The algorithm is undefined and crashes
- C. A further relaxation after V - 1 passes still succeeds
- D. The distances are all zero
Correct answer: C. A further relaxation after V - 1 passes still succeeds
After V - 1 passes a reachable negative cycle always allows one more improvement, which is how it is detected.
More Coding Interview Problems questions
- Problem: What is the minimum number of colours needed to colour a bipartite graph so that no adjacent vertices share a colour?
- Problem: Which operation does the 'pointer jumping' technique speed up in parallel algorithms, and what is its complexity?
- Problem: Which problem asks for the number of ways to walk exactly k steps on a graph from u to v?
- Problem: What is the purpose of path compression in a union-find structure?
- Problem: Which structure answers 'number of points in a rectangle' queries offline in O(log n) each using sorting and a Fenwick tree?
- Problem: What is the expected depth of a random binary search tree built from n distinct keys?