Data Structures & AlgorithmsHardProduct Company SDE · DAG DP

Problem: Which algorithm computes the longest path in a weighted directed acyclic graph in O(V + E)?

  1. A. Dynamic programming over a topological order
  2. B. Floyd-Warshall
  3. C. Kruskal's algorithm
  4. D. Dijkstra with a max-heap

Correct answer: A. Dynamic programming over a topological order

Processing vertices in topological order lets each DP value depend only on already-final predecessors.

More Coding Interview Problems questions

Exams that ask this topic