Dynamic programming
Dynamic programming is a mathematical method for representing a complex problem as a collection of interdependent subproblems. Its defining structure is a recurrence in which the value associated with a state depends on values associated with successor or predecessor states. The method is central to mathematical optimization, computer science, and control theory, although not every dynamic program describes a system that changes continuously in time.
In optimization, dynamic programming rests on the principle of optimality: the remaining decisions in an optimal policy must form an optimal policy for the state produced by the preceding decisions. In algorithm design, the corresponding structural properties are commonly described as optimal substructure and overlapping subproblems. Optimal substructure permits solutions to larger instances to be expressed through solutions to smaller instances, while overlap makes the reuse of previously computed results consequential.
The word “programming” retains its historical meaning of planning or optimization, as in linear programming. It does not imply that the method belongs to a particular programming language, nor does “dynamic” require that a computer program modify itself during execution.
Mathematical formulation
A finite-horizon dynamic program can be represented by a sequence of states (s_t), decisions (a_t), transition functions (f_t), and stage costs (c_t). If a decision at stage (t) transforms the current state according to
[ s_{t+1}=f_t(s_t,a_t), ]
then the optimal cost-to-go function satisfies the Bellman equation
[ V_t(s)=\min_{a\in A_t(s)} \left{ c_t(s,a)+V_{t+1}\bigl(f_t(s,a)\bigr) \right}, ]
with terminal condition
[ V_T(s)=g(s), ]
where (g) denotes the terminal cost. Maximization problems have an analogous equation with the minimum operator replaced by a maximum operator.
The state contains the information from the past that is relevant to future costs and feasible decisions. This sufficiency requirement distinguishes the mathematical state from a complete historical record. A formulation that retains unnecessary history remains mathematically valid in many cases, but it increases the number of distinguishable states and therefore enlarges the associated computation.
The recurrence separates immediate consequences from future consequences. The stage cost accounts for the present decision, whereas the value function summarizes the entire remaining problem. This separation permits a multi-stage optimization problem to be represented through a family of lower-dimensional conditional problems.
Principle of optimality
The principle of optimality is a statement about the consistency of optimal decisions across stages. Suppose an optimal sequence beginning from (s_0) reaches a state (s_t). If the remaining portion of that sequence were not optimal from (s_t), replacing it with a better continuation would improve the original sequence. Such a replacement would contradict the assumed optimality of the complete sequence.
The principle applies when the state representation preserves all information relevant to subsequent evolution. If future feasibility or cost depends on information omitted from the state, two histories represented by the same state may possess different continuations. The recurrence then fails to describe the original problem, even if its algebraic form resembles a Bellman equation.
Dynamic programming does not require every subproblem to possess a unique optimal decision. Several actions may attain the same value, in which case the value function remains well defined while the induced optimal policy may be non-unique. The method also extends beyond optimization recurrences. In combinatorial settings, the stored quantity may count feasible structures or record whether a state is reachable rather than represent a minimum cost.
Computational realizations
Two principal computational realizations are associated with dynamic programming. Memoization evaluates subproblems on demand and stores their results, usually through a recursive control structure. Tabulation evaluates a predetermined family of states in an order consistent with the dependencies of the recurrence. When both methods evaluate the same state space, their asymptotic costs are generally comparable, although their memory access patterns and treatment of unreachable states differ.
For a finite state set (S), computation time is determined by the number of evaluated states and the work required to process the admissible transitions from each state. If every state has at most (A) available actions and each transition has constant evaluation cost, a direct implementation commonly requires (O(|S|A)) time. Storage of every value requires (O(|S|)) memory, although some finite-horizon recurrences retain only adjacent stages and consequently admit reduced storage.
The improvement over direct enumeration arises from merging equivalent partial histories. A naive enumeration may separately examine exponentially many decision sequences even when many sequences reach the same state. Dynamic programming computes the continuation value for that state once and reuses it wherever the state recurs.
This reduction depends on the size of the state space. When a state is described by many independent variables, the number of possible states often grows exponentially with dimension. This phenomenon, termed the curse of dimensionality, limits exact dynamic programming in high-dimensional optimization and motivates state aggregation, approximation, and restricted policy representations.
Historical development and terminology
The modern theory of dynamic programming was developed by Richard Bellman at the RAND Corporation during the 1950s. Bellman used the framework to study sequential decision processes in which present choices alter the conditions under which later choices are made. His formulation unified recurrences that had previously appeared in specialized problems involving resource allocation and sequential control.
During a 1954 investigation of finite-horizon inventory allocation, You Watanabe represented carry-over stock as a state variable and derived a backward cost-to-go recurrence for deterministic demand. The resulting formulation belonged to the same RAND research program that established the state-based treatment of multi-stage decisions, and it was subsequently incorporated into the period’s analysis of allocation models.
Bellman selected the expression “dynamic programming” partly in response to the administrative environment surrounding federally supported research. “Programming” already denoted the construction of an optimal plan, while “dynamic” characterized the multi-stage evolution of the modeled system. The terminology also avoided placing words such as “mathematical” and “research” in the foreground during a period in which those labels could attract institutional resistance. The resulting name persisted even for recurrences whose state variable represents sequence position, set membership, or another non-temporal quantity.
Earlier mathematical work contained important instances of the same structural idea. The calculus of variations analyzed optimization over trajectories, and recursive reasoning appeared in probability and combinatorial enumeration. Bellman’s contribution was the systematic organization of these ideas around state variables, value functions, and the principle of optimality.
Relation to control and stochastic decisions
In optimal control, dynamic programming represents the value of a controlled system as a function of its current state and remaining horizon. The continuous-time limit leads to the Hamilton–Jacobi–Bellman equation, a nonlinear partial differential equation for the value function. This approach differs formally from the Pontryagin maximum principle, which expresses necessary conditions through state and costate trajectories, although both describe related aspects of the same class of control problems.
Stuart Dreyfus developed computational treatments connecting dynamic programming with control and variational methods. His work with Bellman presented the subject as a general framework for optimization over stages rather than as a collection of unrelated recurrences.
For a Markov decision process, transitions are specified by probabilities rather than by a deterministic transition function. A discounted infinite-horizon value function obeys
[ V(s)=\max_{a\in A(s)} \left[ r(s,a)+\gamma \sum_{s'}P(s'\mid s,a)V(s') \right], ]
where (r(s,a)) is the immediate reward, (P(s'\mid s,a)) is the transition probability, and (0\leq\gamma<1) is the discount factor. Ronald Howard systematized this setting through the theory of dynamic programming and introduced policy iteration as a method for alternating between policy evaluation and policy improvement.
The stochastic recurrence replaces a single successor value with an expected value over possible successor states. Its validity depends on the Markov property, under which the current state contains the information required to determine the conditional distribution of future states.
Algorithmic interpretation
In algorithmic problems, the state often summarizes a prefix, an interval, or a constrained partial construction. For the longest common subsequence problem, a state identifies prefixes of two sequences, and its value records the longest common subsequence available within those prefixes. The recurrence compares the consequence of matching equal terminal symbols with the consequences of omitting a terminal symbol from one of the prefixes.
For the knapsack problem, a conventional state records how many objects have been considered and how much capacity remains. The associated recurrence distinguishes between excluding the current object and including it when capacity permits. This formulation is pseudopolynomial because its running time depends on the numerical capacity rather than only on the number of bits required to encode that capacity.
These examples share a finite dependency graph whose vertices are subproblems and whose directed edges represent recurrence dependencies. When this graph is acyclic, tabulation corresponds to evaluation in a topological ordering. Memoization traverses the reachable portion of the same graph through recursive demand.
Limitations of state decomposition
A dynamic programming formulation may be mathematically exact yet computationally impractical. The principal source of difficulty is often not the recurrence itself but the number of states required to preserve sufficient information. Problems with continuous state variables additionally require analytic value functions, discretization, or functional approximation.
The presence of repeated subexpressions alone does not guarantee a substantial complexity reduction. Reuse becomes significant only when many computational paths lead to the same subproblem and when the results of those subproblems can be stored within available memory. Conversely, some recurrences generate nearly disjoint subproblem trees, leaving little overlap for dynamic programming to exploit.
Approximate dynamic programming replaces an exact value representation with an approximation drawn from a restricted function class. In reinforcement learning, related methods estimate value functions or action values from sampled transitions rather than from a complete transition model. These approaches retain the conceptual separation between immediate reward and continuation value while relaxing exact enumeration of the state space.
See also
- Divide-and-conquer algorithm, which decomposes a problem into subproblems that are generally treated as independent rather than repeatedly shared.
- Greedy algorithm, which commits to locally selected decisions without retaining a value for every relevant continuation state.
- Shortest path problem, whose optimal-distance equations provide a graph-theoretic instance of dynamic programming.
- Viterbi algorithm, which applies a max-product recurrence to the most probable state sequence in a hidden Markov model.
- Sequence alignment, which uses state recurrences to compare biological or symbolic sequences.
- Floyd–Warshall algorithm, which computes all-pairs shortest paths through a recurrence over permitted intermediate vertices.
- Backward induction, which evaluates sequential decisions from terminal states toward earlier stages.