Math 2.0

Operations research, mathematical programming Definition

Dynamic programming

Builds on AlgorithmRecurrence relationPartial order

Definition

A dynamic programming algorithm for a function FF consists of:

  1. a finite set SS of subproblems with a strict partial order ≺\prec on SS and a target subproblem s∗∈Ss^* \in S;
  2. a recurrence that gives the value v(s)v(s) of each s∈Ss \in S as an explicit function of ss and of the values v(s′)v(s') of finitely many s′≺ss' \prec s;
  3. a guarantee that F(input)=v(s∗)F(\text{input}) = v(s^*).

The algorithm computes the values v(s)v(s) in an order compatible with ≺\prec, bottom-up in a table or top-down with memoization. It stores each value once and returns v(s∗)v(s^*). Its running time is at most the sum over s∈Ss \in S of the cost of evaluating the recurrence at ss.

Remarks

The method pays off when subproblems overlap, that is, when the same v(s′)v(s') is needed for many ss. For optimization problems, the correctness of the recurrence in clause 2 rests on the principle of optimality: an optimal solution restricted to a subproblem is optimal for that subproblem.

Example: the longest common subsequence of strings x=x1⋯xmx = x_1 \cdots x_m and y=y1⋯yny = y_1 \cdots y_n. Take S={0,…,m}×{0,…,n}S = \set{0, \dots, m} \times \set{0, \dots, n} with (i′,j′)≺(i,j)(i', j') \prec (i, j) when i′≤ii' \le i, j′≤jj' \le j and (i′,j′)≠(i,j)(i', j') \ne (i, j), and target (m,n)(m, n). Then v(i,0)=v(0,j)=0v(i, 0) = v(0, j) = 0, v(i,j)=v(i−1,j−1)+1v(i, j) = v(i-1, j-1) + 1 if xi=yjx_i = y_j, and v(i,j)=max⁡(v(i−1,j),v(i,j−1))v(i, j) = \max(v(i-1, j), v(i, j-1)) otherwise. The table has (m+1)(n+1)(m+1)(n+1) entries, each computed in constant time, so the algorithm runs in time O(mn)O(mn), while trying all subsequences of xx would take time exponential in mm.

Non-example: a recurrence in which some v(s)v(s) depends on itself through a cycle of dependencies, such as v(s)=v(s)+1v(s) = v(s) + 1, fails clause 2. It would need s≺ss \prec s, which a strict partial order forbids, so no evaluation order makes all the inputs of such a v(s)v(s) available first.

Reading path

To understand this page from the ground up, read these 4 pages in order. The foundations come first.

Show the path as a graph
Each page uses the pages above it. The colour of the bar on a box shows how strong the evidence is, and the box also gives it as text. The list has the same pages.
  • no evidence level
  1. Algorithm concept
  2. Partial order concept
  3. Recurrence relation concept
  4. Dynamic programming definition

Further reading

  1. Web https://en.wikipedia.org/wiki/Dynamic_programming
About this page
Tag8E1CJZXC6X
URIm2://8E1CJZXC6X
Kinddefinition
WritingW0 stub
MSC90C39, 68W40
DefinesDynamic programming
UsesAlgorithm, Recurrence relation, Partial order
Changed3 November 2026

Markdown · JSON · Edit on GitHub

What this page needs for W1

  • a source with a locator (0 of 1)

The writing levels say how complete the text of a page is. They do not measure its truth.

What links here

No page links to this page yet.