Graph Theory37 sections · 1633 units
Open in Course

Why DAGs Are Special

No cycles = DP works

If a graph has a cycle, there is no "first" node to start from.

But in a DAG, you can always find a topological order: an ordering where every edge goes from left to right. This ordering lets you solve DP problems in one pass. Process nodes in topological order, and when you reach a node, all its dependencies are already solved. No cycles means no circular dependencies. That is why DP works on DAGs.