Data Structures & AlgorithmsHardICPC regional · shortest path
Problem: What is the worst-case complexity of the SPFA (queue-based Bellman-Ford) shortest path algorithm?
- A. O(VE)
- B. O(E log V)
- C. O(V^2)
- D. O(E + V)
Correct answer: A. O(VE)
Each vertex can be re-enqueued up to V times with E relaxations per pass, giving O(VE) in the worst case.
More Coding Interview Problems questions
- Problem: Which property must hold for Huffman coding to produce an optimal prefix code?
- Problem: What is the complexity of Kruskal's algorithm when edges are already sorted and union-find uses path compression and union by rank?
- Problem: What does the Kuhn-Munkres (Hungarian) algorithm compute on a bipartite graph with weights?
- Problem: Which approach computes the number of distinct substrings of a string of length n in O(n log n) with a suffix array?
- Problem: Which graph algorithm checks whether a directed graph is a DAG in O(V + E)?
- Problem: What is the expected number of comparisons for a binary search on a sorted array of n = 1000 elements (successful search, worst…