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?

  1. A. Relaxation in topological order
  2. B. Dijkstra's algorithm
  3. C. Bellman-Ford
  4. 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

Exams that ask this topic