Data Structures & AlgorithmsHardProduct Company SDE · DAG shortest path
Problem: Which algorithm solves the single-source shortest path problem in O(E) time on a directed acyclic graph with arbitrary edge weights?
- A. Relaxation in topological order
- B. Dijkstra's algorithm
- C. Bellman-Ford
- D. Kruskal's algorithm
Correct answer: A. Relaxation in topological order
A topological order guarantees every predecessor is final before its outgoing edges are relaxed, giving O(V + E).
More Coding Interview Problems questions
- Problem: Which statement about the Edmonds-Karp algorithm's number of augmentations is correct?
- Problem: Which problem is solved by the Floyd-Warshall algorithm in the presence of negative edges but no negative cycle?
- Problem: What is the running time of Prim's algorithm with a binary heap on a connected graph with V vertices and E edges?
- Problem: What is the maximum number of edges in a simple planar graph with V >= 3 vertices?
- Problem: Which theorem states that every tree on n vertices has exactly n - 1 edges?
- Problem: What is the number of spanning trees of a cycle graph Cn with n vertices?