Data Structures & AlgorithmsVery hardICPC regional · algorithm theory
Problem: Johnson's algorithm reweights edges with potentials before running Dijkstra. What does the reweighting achieve?
- A. It removes all cycles from the graph
- B. It doubles every weight
- C. It converts the graph to a tree
- D. It makes all edge weights non-negative without changing shortest paths
Correct answer: D. It makes all edge weights non-negative without changing shortest paths
Potentials h(v) from Bellman-Ford give w'(u,v) = w(u,v) + h(u) - h(v) >= 0, and shortest paths are preserved.
More Coding Interview Problems questions
- Problem: Range-add updates and point queries on an array can be done with a Fenwick tree over which representation?
- Problem: What is the expected time of Rabin-Karp string matching with a good polynomial hash?
- Problem: How many pairs (i < j) of the array 1..14 have a[i] + a[j] divisible by 7? Run the code. python a = list(range(1, 15))…
- Problem: Which is the worst-case time complexity of the median-of-medians selection algorithm for finding the k-th smallest element of n…
- Problem: What is the worst-case number of comparisons to merge two sorted lists of lengths m and n?
- Problem: For coprime m and n, which identity for Euler's totient function is correct?