The Grand Unification
Dynamic programming is just finding the shortest or longest path in a Directed Acyclic Graph (DAG).
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Understand the fundamental relationship between Dynamic Programming and Graph Theory.
Dynamic programming is just finding the shortest or longest path in a Directed Acyclic Graph (DAG).
Every subproblem (e.g. `dp[i][j]`) is a node in the graph. The number of states is the number of vertices |V|.
The recursive call (e.g. `dp[i-1][j]`) is a directed edge between nodes. The number of choices is the out-degree.
DP only works if there are no cycles (infinite loops in recursion). Hence, the graph of dependencies must be a DAG.