Graph Theory37 sections · 1633 units
Open in Course

When DAG DP Fails

Cycles break the pattern

DP on DAGs assumes you can order nodes so each depends only on earlier nodes. Cycles break this because uu depends on vv and vv depends on uu. For shortest paths with cycles, use Dijkstra (no negative weights) or Bellman-Ford (handles negative weights).

For longest paths with cycles, you need cycle detection first. If the graph has cycles but you know it is a DAG (problem statement guarantees it), you can use DP confidently. Otherwise, check for cycles before applying DP.