Data Structures & AlgorithmsModerateProduct Company SDE · DAG DP

Problem: What is the complexity of computing the number of distinct paths in a DAG with V vertices and E edges by DP?

  1. A. O(V^3)
  2. B. O(2^V)
  3. C. O(E log V)
  4. D. O(V + E)

Correct answer: D. O(V + E)

Each vertex and edge is processed once in topological order, so the DP is linear.

More Coding Interview Problems questions

Exams that ask this topic