Data Structures & AlgorithmsHardICPC regional · algorithm theory
Problem: In Bellman-Ford, which statement about early termination is correct?
- A. The algorithm can stop after the first pass whenever a negative edge exists
- B. Early termination is impossible on graphs with negative weights
- C. It stops once the source has no outgoing edges
- D. If one full pass relaxes no edge, all distances are final and the algorithm can stop
Correct answer: D. If one full pass relaxes no edge, all distances are final and the algorithm can stop
No relaxation in a pass means every edge satisfies the shortest-path condition, so further passes cannot change anything.
More Coding Interview Problems questions
- Problem: What is the time complexity of Prim's algorithm on a graph stored as an adjacency matrix with V vertices?
- Problem: By the Sprague-Grundy theorem, what is the Grundy value of a sum of independent impartial games?
- Problem: What is the minimum number of comparisons in the worst case to find both the maximum and the minimum of n = 10 distinct elements…
- Problem: What is the information-theoretic lower bound on comparisons (in the worst case) for sorting 5 distinct elements?
- Problem: Which of the following decision problems is NP-complete?
- Problem: Which statement about the subset-sum problem with target S and n items is correct in the standard sense?