Practice Discrete Math

Algorithms / Dp Subproblem Graph

Least You Need to Know: DP as a Subproblem Graph

A recurrence defines a directed graph of dependencies between states. Thinking of DP as a DAG clarifies overlapping subproblems, iteration order, and why cycles are a warning sign.

The least you need to know

Key notation

state graph graph whose nodes are subproblems
A → B state A depends on previously solving state B
topological order an order that respects every dependency edge

Tiny worked example

  • In Fibonacci, state `n` depends on states `n-1` and `n-2`.
  • The subproblem graph is a DAG that points from larger indices to smaller ones.
  • Memoization caches repeated visits to the same smaller nodes.
  • Tabulation fills those nodes first and works upward.

Common mistakes

How to recognize this kind of problem

Start practice