Dynamic programming: Difference between revisions

Content deleted Content added
m Fixed reference links that were broken
 
(109 intermediate revisions by 81 users not shown)
Line 1:
{{Short description|Problem optimization method}}
{{Distinguish|Dynamic programming language|Dynamic problem}}
{{bots|deny=OAbot}}<!-- To prevent re-addition of bogus pmc -->
[[File:Shortest path optimal substructure.svg|thumb|200px|'''Figure 1.''' Finding the shortest path in a graph using optimal substructure; a straight line indicates a single edge; a wavy line indicates a shortest path between the two vertices it connects (among other paths, not shown, sharing the same two vertices); the bold line is the overall shortest path from start to goal.]]
[[File:Shortest path optimal substructure.svg|thumb|upright=0.8|'''Figure 1.''' Finding the shortest path in a graph using optimal substructure; a straight line indicates a single edge; a wavy line indicates a shortest path between the two vertices it connects (among other paths, not shown, sharing the same two vertices); the bold line is the overall shortest path from start to goal.]]
 
'''Dynamic programming''' is both a [[mathematical optimization]] method and aan computer[[algorithmic programming methodparadigm]]. The method was developed by [[Richard Bellman]] in the 1950s and has found applications in numerous fields, from [[aerospace engineering]] to [[economics]].
 
In both contexts it refers to simplifying a complicated problem by breaking it down into simpler sub-problems in a [[Recursion|recursive]] manner. While some decision problems cannot be taken apart this way, decisions that span several points in time do often break apart recursively. Likewise, in computer science, if a problem can be solved optimally by breaking it into sub-problems and then recursively finding the optimal solutions to the sub-problems, then it is said to have ''[[optimal substructure]]''.
 
If sub-problems can be nested recursively inside larger problems, so that dynamic programming methods are applicable, then there is a relation between the value of the larger problem and the values of the sub-problems.<ref name=":0">Cormen, T. H.; Leiserson, C. E.; Rivest, R. L.; Stein, C. (2001), Introduction to Algorithms (2nd ed.), MIT Press & McGraw–Hill, {{ISBN|0-262-03293-7}} . pp. 344.</ref> In the optimization literature this relationship is called the [[Bellman equation]].
Line 11 ⟶ 13:
 
=== Mathematical optimization ===
In terms of mathematical optimization, dynamic programming usually refers to simplifying a decision by breaking it down into a sequence of decision steps over time.

This is done by defining a sequence of '''value functions''' ''V''<sub>1</sub>, ''V''<sub>2</sub>, ..., ''V''<sub>''n''</sub> taking ''y'' as an argument representing the '''[[State variable|state]]''' of the system at times ''i'' from 1 to ''n''.

The definition of ''V''<sub>''n''</sub>(''y'') is the value obtained in state ''y'' at the last time ''n''.

The values ''V''<sub>''i''</sub> at earlier times ''i''&nbsp;=&nbsp;''n''&nbsp;&minus;1,&nbsp;''n''&nbsp;&minus;&nbsp;2,&nbsp;...,&nbsp;2,&nbsp;1 can be found by working backwards, using a [[Recursion|recursive]] relationship called the [[Bellman equation]].

For ''i''&nbsp;=&nbsp;2,&nbsp;...,&nbsp;''n'', ''V''<sub>''i''&minus;1</sub> at any state ''y'' is calculated from ''V''<sub>''i''</sub> by maximizing a simple function (usually the sum) of the gain from a decision at time ''i''&nbsp;&minus;&nbsp;1 and the function ''V''<sub>''i''</sub> at the new state of the system if this decision is made. Since ''V''<sub>''i''</sub> has already been calculated for the needed states, the above operation yields ''V''<sub>''i''&minus;1</sub> for those states. Finally, ''V''<sub>1</sub> at the initial state of the system is the value of the optimal solution. The optimal values of the decision variables can be recovered, one by one, by tracking back the calculations already performed.
 
Since ''V''<sub>''i''</sub> has already been calculated for the needed states, the above operation yields ''V''<sub>''i''&minus;1</sub> for those states.
 
Finally, ''V''<sub>1</sub> at the initial state of the system is the value of the optimal solution. The optimal values of the decision variables can be recovered, one by one, by tracking back the calculations already performed.
 
=== Control theory ===
Line 18 ⟶ 32:
The solution to this problem is an optimal control law or policy <math>\mathbf{u}^{\ast} = h(\mathbf{x}(t), t)</math>, which produces an optimal trajectory <math>\mathbf{x}^{\ast}</math> and a [[cost-to-go function]] <math>J^{\ast}</math>. The latter obeys the fundamental equation of dynamic programming:
:<math>- J_{t}^{\ast} = \min_{\mathbf{u}} \left\{ f \left( \mathbf{x}(t), \mathbf{u}(t), t \right) + J_{x}^{\ast \mathsf{T}} \mathbf{g} \left( \mathbf{x}(t), \mathbf{u}(t), t \right) \right\}</math>
a [[partial differential equation]] known as the [[Hamilton–Jacobi–Bellman equation]], in which <math>J_{x}^{\ast} = \frac{\partial J^{\ast}}{\partial \mathbf{x}} = \left[ \frac{\partial J^{\ast}}{\partial x_{1}} ~~~~ \frac{\partial J^{\ast}}{\partial x_{2}} ~~~~ \dots ~~~~ \frac{\partial J^{\ast}}{\partial x_{n}} \right]^{\mathsf{T}}</math> and <math>J_{t}^{\ast} = \frac{\partial J^{\ast}}{\partial t}</math>. One finds thethat minimizing <math>\mathbf{u}</math> in terms of <math>t</math>, <math>\mathbf{x}</math>, and the unknown function <math>J_{x}^{\ast}</math> and then substitutes the result into the Hamilton–Jacobi–Bellman equation to get the partial differential equation to be solved with boundary condition <math>J \left( t_{1} \right) = b \left( \mathbf{x}(t_{1}), t_{1} \right)</math>.<ref>{{cite book |firstfirst1=M. I. |lastlast1=Kamien |authorlinkauthor-link=Morton Kamien |first2=N. L. |last2=Schwartz |authorlink2author-link2=Nancy Schwartz |title=Dynamic Optimization: The Calculus of Variations and Optimal Control in Economics and Management |___location=New York |publisher=Elsevier |edition=Second |year=1991 |isbn=978-0-444-01609-6 |url=https://books.google.com/books?id=0IoGUn8wjDQC&pg=PA261 |page=261 }}</ref> In practice, this generally requires [[Numerical partial differential equations|numerical techniques]] for some discrete approximation to the exact optimization relationship.
 
Alternatively, the continuous process can be approximated by a discrete system, which leads to a following recurrence relation analog to the Hamilton–Jacobi–Bellman equation:
:<math>J_{k}^{\ast} \left( \mathbf{x}_{n-k} \right) = \min_{\mathbf{u}_{n-k}} \left\{ \hat{f} \left( \mathbf{x}_{n-k}, \mathbf{u}_{n-k} \right) + J_{k-1}^{\ast} \left( \hat{\mathbf{g}} \left( \mathbf{x}_{n-k}, \mathbf{u}_{n-k} \right) \right) \right\}</math>
at the <math>k</math>-th stage of <math>n</math> equally spaced discrete time intervals, and where <math>\hat{f}</math> and <math>\hat{\mathbf{g}}</math> denote discrete approximations to <math>f</math> and <math>\mathbf{g}</math>. This functional equation is known as the [[Bellman equation]], which can be solved for an exact solution of the discrete approximation of the optimization equation.<ref>{{cite book |first=Donald E. |last=Kirk |title=Optimal Control Theory: An Introduction |___location=Englewood Cliffs, NJ |publisher=Prentice-Hall |year=1970 |isbn=978-0-13-638098-6 |pages=94–95 |url=https://books.google.com/books?id=fCh2SAtWIdwC&pg=PA94 }}</ref>
 
==== Example from economics: Ramsey's problem of optimal saving ====
{{See also|Ramsey–Cass–Koopmans model}}
In [[economics]], the objective is generally to maximize (rather than minimize) some dynamic [[social welfare function]]. In Ramsey's problem, this function relates amounts of consumption to levels of [[utility]]. Loosely speaking, the planner faces the trade-off between contemporaneous consumption and future consumption (via investment in [[Physical capital|capital stock]] that is used in production), known as [[intertemporal choice]]. Future consumption is discounted at a constant rate <math>\beta \in (0,1)</math>. A discrete approximation to the transition equation of capital is given by
:<math>k_{t+1} = \hat{g} \left( k_{t}, c_{t} \right) = f(k_{t}) - c_{t}</math>
where <math>c</math> is consumption, <math>k</math> is capital, and <math>f</math> is a [[production function]] satisfying the [[Inada conditions]]. An initial capital stock <math>k_{0} > 0</math> is assumed.
Line 68 ⟶ 82:
We see that it is optimal to consume a larger fraction of current wealth as one gets older, finally consuming all remaining wealth in period {{mvar|T}}, the last period of life.
 
=== Computer programmingscience ===
There are two key attributes that a problem must have in order for dynamic programming to be applicable: [[optimal substructure]] and [[overlapping subproblem|overlapping sub-problem]]s. If a problem can be solved by combining optimal solutions to ''non-overlapping'' sub-problems, the strategy is called "[[Divide and conquer algorithm|divide and conquer]]" instead.<ref name=":0" /> This is why [[mergesort|merge sort]] and [[quicksort|quick sort]] are not classified as dynamic programming problems.
 
''Optimal substructure'' means that the solution to a given optimization problem can be obtained by the combination of optimal solutions to its sub-problems. Such optimal substructures are usually described by means of [[recursion]]. For example, given a graph ''G=(V,E)'', the shortest path ''p'' from a vertex ''u'' to a vertex ''v'' exhibits optimal substructure: take any intermediate vertex ''w'' on this shortest path ''p''. If ''p'' is truly the shortest path, then it can be split into sub-paths ''p<sub>1</sub>'' from ''u'' to ''w'' and ''p<sub>2</sub>'' from ''w'' to ''v'' such that these, in turn, are indeed the shortest paths between the corresponding vertices (by the simple cut-and-paste argument described in ''[[Introduction to Algorithms]]''). Hence, one can easily formulate the solution for finding shortest paths in a recursive manner, which is what the [[Bellman–Ford algorithm]] or the [[Floyd–Warshall algorithm]] does.
 
''Overlapping'' sub-problems means that the space of sub-problems must be small, that is, any recursive algorithm solving the problem should solve the same sub-problems over and over, rather than generating new sub-problems. For example, consider the recursive formulation for generating the Fibonacci seriessequence: ''F''<sub>''i''</sub> = ''F''<sub>''i''&minus;1</sub> + ''F''<sub>''i''&minus;2</sub>, with base case ''F''<sub>1</sub>&nbsp;=&nbsp;''F''<sub>2</sub>&nbsp;=&nbsp;1. Then ''F''<sub>43</sub> =&nbsp;''F''<sub>42</sub>&nbsp;+&nbsp;''F''<sub>41</sub>, and ''F''<sub>42</sub> =&nbsp;''F''<sub>41</sub>&nbsp;+&nbsp;''F''<sub>40</sub>. Now ''F''<sub>41</sub> is being solved in the recursive sub-trees of both ''F''<sub>43</sub> as well as ''F''<sub>42</sub>. Even though the total number of sub-problems is actually small (only 43 of them), we end up solving the same problems over and over if we adopt a naive recursive solution such as this. Dynamic programming takes account of this fact and solves each sub-problem only once.
 
[[Image:Fibonacci dynamic programming.svg|thumb|108px|'''Figure 2.''' The subproblem graph for the Fibonacci sequence. The fact that it is not a [[tree structure|tree]] indicates overlapping subproblems.]]
 
This can be achieved in either of two ways:<ref>{{CitationCite web needed|title=Algorithms by Jeff Erickson |url=https://jeffe.cs.illinois.edu/teaching/algorithms/ |access-date=June2024-12-06 2009|website=jeffe.cs.illinois.edu}}</ref>
 
* ''[[Top-down and bottom-up design|Top-down approach]]'': This is the direct fall-out of the recursive formulation of any problem. If the solution to any problem can be formulated recursively using the solution to its sub-problems, and if its sub-problems are overlapping, then one can easily [[memoize]] or store the solutions to the sub-problems in a table (often an [[Array (data structure)|array]] or [[Hash table|hashtable]] in practice). Whenever we attempt to solve a new sub-problem, we first check the table to see if it is already solved. If a solution has been recorded, we can use it directly, otherwise we solve the sub-problem and add its solution to the table.
* ''[[Top-down and bottom-up design|Bottom-up approach]]'': Once we formulate the solution to a problem recursively as in terms of its sub-problems, we can try reformulating the problem in a bottom-up fashion: try solving the sub-problems first and use their solutions to build-on and arrive at solutions to bigger sub-problems. This is also usually done in a tabular form by iteratively generating solutions to bigger and bigger sub-problems by using the solutions to small sub-problems. For example, if we already know the values of ''F''<sub>41</sub> and ''F''<sub>40</sub>, we can directly calculate the value of ''F''<sub>42</sub>.
 
Some [[programming language]]s can automatically [[memoization|memoize]] the result of a function call with a particular set of arguments, in order to speed up [[call-by-name]] evaluation (this mechanism is referred to as ''[[call-by-need]]''). Some languages make it possible portably (e.g. [[Scheme (programming language)|Scheme]], [[Common Lisp]], [[Perl]] or [[D (programming language)|D]]). Some languages have automatic [[memoization]] <!-- still not a typo for "memor-" --> built in, such as tabled [[Prolog]] and [[J (programming language)|J]], which supports memoization with the ''M.'' adverb.<ref>{{cite web|title=M. Memo|url=http://www.jsoftware.com/help/dictionary/dmcapdot.htm|work=J Vocabulary|publisher=J Software|accessdateaccess-date=28 October 2011}}</ref> In any case, this is only possible for a [[referentially transparent]] function. Memoization is also encountered as an easily accessible design pattern within term-rewrite based languages such as [[Wolfram Language]].
 
=== Bioinformatics ===
Dynamic programming is widely used in bioinformatics for the tasks such as [[sequence alignment]], [[protein folding]], RNA structure prediction and protein-DNA binding. The first dynamic programming algorithms for protein-DNA binding were developed in the 1970s independently by [[Charles DeLisi]] in USA<ref>DeLisi,the Biopolymers, 1974, Volume 13, Issue 7, pages 1511–1512, July 1974US</ref> and Georgii Gurskii and Alexander Zasedatelev in USSR.<ref>Gurskiĭ GV, Zasedatelev AS, Biofizika, 1978 Sep-Oct;23(5):932-46</ref> Recently these algorithms have become very popular in bioinformatics and computational biology, particularly in the studies of [[nucleosome]] positioning and [[transcription factor]] binding.{{citation
| last = Delisi | first = Charles
| date = July 1974
| doi = 10.1002/bip.1974.360130719
| issue = 7
| journal = Biopolymers
| pages = 1511–1512
| title = Cooperative phenomena in homopolymers: An alternative formulation of the partition function
| volume = 13}}</ref> and by Georgii Gurskii and Alexander Zasedatelev in the [[Soviet Union]].<ref>{{citation
| last1 = Gurskiĭ | first1 = G. V.
| last2 = Zasedatelev | first2 = A. S.
| date = September 1978
| issue = 5
| journal = Biofizika
| pages = 932–946
| pmid = 698271
| title = Precise relationships for calculating the binding of regulatory proteins and other lattice ligands in double-stranded polynucleotides
| volume = 23}}</ref> Recently these algorithms have become very popular in bioinformatics and [[computational biology]], particularly in the studies of [[nucleosome]] positioning and [[transcription factor]] binding.
 
== Examples: Computercomputer algorithms ==
 
=== Dijkstra's algorithm for the shortest path problem ===
From a dynamic programming point of view, [[Dijkstra's algorithm]] for the [[shortest path problem]] is a successive approximation scheme that solves the dynamic programming functional equation for the shortest path problem by the '''Reaching''' method.<ref name=sniedovich_06>{{Citation | last = Sniedovich | first = M. | title = Dijkstra's algorithm revisited: the dynamic programming connexion | journal = Journal of Control and Cybernetics | volume = 35 | issue = 3 | pages = 599–620 | year = 2006 | url = http://matwbn.icm.edu.pl/ksiazki/cc/cc35/cc3536.pdf | postscript = .}} [http://www.ifors.ms.unimelb.edu.au/tutorial/dijkstra_new/index.html Online version of the paper with interactive computational modules.]</ref><ref name=denardo_03>{{Citation | last = Denardo | first = E.V. | title = Dynamic Programming: Models and Applications | publisher = [[Dover Publications]] | ___location = Mineola, NY | year = 2003 | isbn = 978-0-486-42810-9}}</ref><ref name=sniedovich_10>{{Citation | last = Sniedovich | first = M. | title = Dynamic Programming: Foundations and Principles | publisher = [[Taylor & Francis]] | year = 2010 | isbn = 978-0-8247-4099-3 }}</ref>
 
In fact, Dijkstra's explanation of the logic behind the algorithm,<ref>{{harvnbcite journal |last=Dijkstra |first=E. W.|author-link=Edsger W. Dijkstra|title=A note on two problems in connexion with graphs |journal=Numerische Mathematik |date=December 1959 |volume=1 |issue=1 |pages=269–271 |pdoi=27010.1007/BF01386390}}</ref> namely
{{quoteblockquote|
'''Problem 2.''' Find the path of minimum total length between two given nodes <math>P</math> and <math>Q</math>.
 
Line 102 ⟶ 133:
 
=== Fibonacci sequence ===
 
Using dynamic programming in the calculation of the ''n''th member of the [[Fibonacci sequence]] improves its performance greatly. Here is a naïve implementation, based directly on the mathematical definition:
 
'''function''' fib(n)
'''if''' n <= 1 '''return''' n
'''return''' fib(n − 1) + fib(n − 2)
 
Notice that if we call, say, <code>fib(5)</code>, we produce a call tree that calls the function on the same value many different times:
Line 121 ⟶ 151:
Now, suppose we have a simple [[Associative array|map]] object, ''m'', which maps each value of <code>fib</code> that has already been calculated to its result, and we modify our function to use it and update it. The resulting function requires only [[Big-O notation|O]](''n'') time instead of exponential time (but requires [[Big-O notation|O]](''n'') space):
 
'''var''' m := '''''map'''''(0 → 0, 1 → 1)
'''function''' fib(n)
'''if ''key''''' n '''is not in ''map''''' m
m[n] := fib(n − 1) + fib(n − 2)
'''return''' m[n]
 
This technique of saving values that have already been calculated is called ''[[memoization]]''; <!-- Yes, memoization, not memorization. Not a typo. --> this is the top-down approach, since we first break the problem into subproblems and then calculate and store values.
Line 131 ⟶ 161:
In the '''bottom-up''' approach, we calculate the smaller values of <code>fib</code> first, then build larger values from them. This method also uses O(''n'') time since it contains a loop that repeats n − 1 times, but it only takes constant (O(1)) space, in contrast to the top-down approach which requires O(''n'') space to store the map.
 
'''function''' fib(n)
'''if''' n = 0
'''return''' 0
'''else'''
'''var''' previousFib := 0, currentFib := 1
'''repeat''' n − 1 '''times''' ''// loop is skipped if n = 1''
'''var''' newFib := previousFib + currentFib
previousFib := currentFib
currentFib := newFib
'''return''' currentFib
 
In both examples, we only calculate <code>fib(2)</code> one time, and then use it to calculate both <code>fib(4)</code> and <code>fib(3)</code>, instead of computing it every time either of them is evaluated.
 
The above method actually takes <math>\Omega(n^2)</math> time for large n because addition of two integers with <math>\Omega(n)</math> bits each takes <math>\Omega(n)</math> time. (The ''n''<sup>th</sup> fibonacci number has <math>\Omega(n)</math> bits.) Also, there is a closed form for the Fibonacci sequence, [[Jacques Philippe Marie Binet#Binet's Fibonacci number formula|known as Binet's formula]], from which the <math>n</math>-th term can be [[Computational complexity of mathematical operations|computed]] in approximately <math>O(n(\log n)^2)</math> time, which is more efficient than the above dynamic programming technique. However, the simple recurrence directly gives [[Fibonacci sequence#Matrix form|the matrix form]] that leads to an approximately <math>O(n\log n)</math> algorithm by fast [[matrix exponentiation]].
 
=== A type of balanced 0–1 matrix ===
{{unreferenced section|date=May 2013}}
Consider the problem of assigning values, either zero or one, to the positions of an {{math|<var>n</var> &times; <var>n</var>}} matrix, with {{math|<var>n</var>}} even, so that each row and each column contains exactly {{math|<var>n</var> / 2}} zeros and {{math|<var>n</var> / 2}} ones. We ask how many different assignments there are for a given <math>{{mvar|n</math>}}. For example, when {{math|<var>n</var> {{=}} 4}}, fourfive possible solutions are
 
:<math>\begin{bmatrix}
Line 170 ⟶ 198:
0 & 1 & 1 & 0 \\
1 & 0 & 0 & 1
\end{bmatrix} \text{ and } \begin{bmatrix}
1 & 1 & 0 & 0 \\
1 & 1 & 0 & 0 \\
0 & 0 & 1 & 1 \\
0 & 0 & 1 & 1
\end{bmatrix}.</math>
 
There are at least three possible approaches: [[Brute-force search|brute force]], [[backtracking]], and dynamic programming.
 
Brute force consists of checking all assignments of zeros and ones and counting those that have balanced rows and columns ({{math|<var>n</var> / 2}} zeros and {{math|<var>n</var> / 2}} ones). As there are <math>2^{n^2}</math> possible assignments and <math>\tbinom{n}{n/2}^n</math> possiblesensible assignments, this strategy is not practical except maybe up to <math>n=6</math>.
 
Backtracking for this problem consists of choosing some order of the matrix elements and recursively placing ones or zeros, while checking that in every row and column the number of elements that have not been assigned plus the number of ones or zeros are both at least {{math|<var>n</var> / 2}}. While more sophisticated than brute force, this approach will visit every solution once, making it impractical for {{math|<var>n</var>}} larger than six, since the number of solutions is already 116,963,796,250{{val|116963796250}} for {{math|<var>n</var>}}&nbsp;=&nbsp;8, as we shall see.
 
Dynamic programming makes it possible to count the number of solutions without visiting them all. Imagine backtracking values for the first row – what information would we require about the remaining rows, in order to be able to accurately count the solutions obtained for each first row value? We consider {{math|<var>k</var> &times; <var>n</var>}} boards, where {{math|1 &le; <var>k</var> &le; <var>n</var>}}, whose <math>{{mvar|k</math>}} rows contain <math>n/2</math> zeros and <math>n/2</math> ones. The function ''f'' to which [[memoization]] is applied maps vectors of ''n'' pairs of integers to the number of admissible boards (solutions). There is one pair for each column, and its two components indicate respectively the number of zeros and ones that have yet to be placed in that column. We seek the value of <math> f((n/2, n/2), (n/2, n/2), \ldots (n/2, n/2)) </math> (<math>{{mvar|n</math>}} arguments or one vector of <math>{{mvar|n</math>}} elements). The process of subproblem creation involves iterating over every one of <math>\tbinom{n}{n/2}</math> possible assignments for the top row of the board, and going through every column, subtracting one from the appropriate element of the pair for that column, depending on whether the assignment for the top row contained a zero or a one at that position. If any one of the results is negative, then the assignment is invalid and does not contribute to the set of solutions (recursion stops). Otherwise, we have an assignment for the top row of the {{math|<var>k</var> &times; <var>n</var>}} board and recursively compute the number of solutions to the remaining {{math|(<var>k</var> &minus; 1) &times; <var>n</var>}} board, adding the numbers of solutions for every admissible assignment of the top row and returning the sum, which is being memoized. The base case is the trivial subproblem, which occurs for a {{math|1 &times; <var>n</var>}} board. The number of solutions for this board is either zero or one, depending on whether the vector is a permutation of {{math|<var>n</var> / 2}} <{{math>|(0, 1)</math>}} and {{math|<var>n</var> / 2}} <{{math>|(1, 0)</math>}} pairs or not.
 
For example, in the first two boards shown above the sequences of vectors would be
Line 199 ⟶ 232:
The number of solutions {{OEIS|id=A058527}} is
 
:<math>{{nowrap| 1,\, 2,\, 90,\, {{val|297200,\}}, {{val|116963796250,\}}, {{val|6736218287430460752}}, \ldots </math>...}}
 
Links to the MAPLE implementation of the dynamic programming approach may be found among the [[#External links|external links]].
Line 222 ⟶ 255:
|-
! 1
| – || – || *'''5*''' || – || –
|-
!width="15"| !! style="width:15px;"|1 !! style="width:15px;"|2 !! style="width:15px;"|3 !! style="width:15px;"|4 !! style="width:15px;"|5
Line 283 ⟶ 316:
: <math>q(i,j)=\begin{cases} \infty & j < 1 \text{ or }j > n \\ c(i, j) & i = 1 \\ \min(q(i-1, j-1), q(i-1, j), q(i-1, j+1)) + c(i,j) & \text{otherwise.}\end{cases}</math>
 
The first line of this equation deals with a board modeled as squares indexed on <code>1</code> at the lowest bound and <code>n</code> at the highest bound. The second line specifies what happens at the lastfirst rank; providing a base case. The third line, the recursion, is the important part. It represents the <code>A,B,C,D</code> terms in the example. From this definition we can derive straightforward recursive code for <code>q(i,&nbsp;j)</code>. In the following pseudocode, <code>n</code> is the size of the board, <code>c(i, j)</code> is the cost function, and <code>min()</code> returns the minimum of a number of values:
 
'''function''' minCost(i, j)
Line 295 ⟶ 328:
This function only computes the path cost, not the actual path. We discuss the actual path below. This, like the Fibonacci-numbers example, is horribly slow because it too exhibits the '''overlapping sub-problems''' attribute. That is, it recomputes the same path costs over and over. However, we can compute it much faster in a bottom-up fashion if we store path costs in a two-dimensional array <code>q[i, j]</code> rather than using a function. This avoids recomputation; all the values needed for array <code>q[i, j]</code> are computed ahead of time only once. Precomputed values for <code>(i,j)</code> are simply looked up whenever needed.
 
We also need to know what the actual shortest path is. To do this, we use another array <code>p[i, j]</code>; a ''predecessor array''. This array records the path to any square <code>s</code>. The predecessor of <code>s</code> is modeled as an offset relative to the index (in <code>q[i, j]</code>) of the precomputed path cost of <code>s</code>. To reconstruct the complete path, we lookup the predecessor of <code>s</code>, then the predecessor of that square, then the predecessor of that square, and so on recursively, until we reach the starting square. Consider the following codepseudocode:
 
'''function''' computeShortestPathArrays()
'''for''' x '''from''' 1 '''to''' n
q[1, x] := c(1, x)
'''for''' y '''from''' 1 '''to''' n
q[y, 0] := infinity
q[y, n + 1] := infinity
'''for''' y '''from''' 2 '''to''' n
'''for''' x '''from''' 1 '''to''' n
m := min(q[y-1, x-1], q[y-1, x], q[y-1, x+1])
q[y, x] := m + c(y, x)
'''if''' m = q[y-1, x-1]
p[y, x] := -1
'''else if''' m = q[y-1, x]
p[y, x] := 0
'''else'''
p[y, x] := 1
 
Now the rest is a simple matter of finding the minimum and printing it.
 
'''function''' computeShortestPath()
computeShortestPathArrays()
minIndex := 1
min := q[n, 1]
'''for''' i '''from''' 2 '''to''' n
'''if''' q[n, i] &lt; min
minIndex := i
min := q[n, i]
printPath(n, minIndex)
 
'''function''' printPath(y, x)
'''print'''(x)
'''print'''("&lt;-")
'''if''' y = 2
'''print'''(x + p[y, x])
'''else'''
printPath(y-1, x + p[y, x])
 
=== Sequence alignment ===
Line 348 ⟶ 381:
 
=== Tower of Hanoi puzzle ===
[[Image:Tower of Hanoi.jpeg|300pxupright=1.2|thumb|A model set of the Towers of Hanoi (with 8 disks)]]
[[Image:Tower of Hanoi 4.gif|300pxupright=1.2|thumb|An animated solution of the '''Tower of Hanoi''' puzzle for ''T(4,3)''.]]
The '''[[Tower of Hanoi]]''' or '''Towers of [[Hanoi]]''' is a [[mathematical game]] or [[puzzle]]. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape.
 
Line 368 ⟶ 401:
For n=1 the problem is trivial, namely S(1,h,t) = "move a disk from rod h to rod t" (there is only one disk left).
 
The number of moves required by this solution is 2<sup>''n''</sup>&nbsp;&minus;&nbsp;1. If the objective is to '''maximize''' the number of moves (without cycling) then the dynamic programming [[Bellman equation|functional equation]] is slightly more complicated and 3<sup>''n''</sup>&nbsp;&minus;&nbsp;1 moves are required.<ref>{{Citation |author=Moshe Sniedovich |title= OR/MS Games: 2. The Towers of Hanoi Problem |journal=INFORMS Transactions on Education |volume=3 |issue=1 |year=2002 |pages=34–51 |url=https://doi.org/= 10.1287/ited.3.1.45 |postscript=.|doi-access=free }}</ref>
 
=== Egg dropping puzzle ===
TheA followingfamous is[[puzzle]] relates to dropping eggs from a descriptionbuilding ofto thedetermine instanceat ofwhich thisheight famousthey [[puzzle]]start to break. The following is a description involving N=2 eggs and a building with H=36 floors:<ref>Konhauser J.D.E., Velleman, D., and Wagon, S. (1996). [https://books.google.bycom/books?id=ElSi5V5uS2MC&printsec=frontcover&hl=ru#v=onepage&q&f=false Which way did the Bicycle Go?] Dolciani Mathematical Expositions – No 18. [[The Mathematical Association of America]].</ref>
:Suppose that we wish to know which stories in a 36-story building are safe to drop eggs from, and which will cause the eggs to break on landing (using [[U.S. English]] terminology, in which the first floor is at ground level). We make a few assumptions:
 
Line 394 ⟶ 427:
: ''W''(''n'',''k'') = minimum number of trials required to identify the value of the critical floor under the worst-case scenario given that the process is in state ''s'' = (''n'',''k'').
 
Then it can be shown that<ref name="sniedovich_03">Sniedovich,{{Cite M.journal|doi (2003).= [https://doi.org/10.1287/ited.4.1.48|title = OR/MS Games: 4. The joyJoy of eggEgg-droppingDropping in Braunschweig and Hong Kong].|year = 2003|last1 = Sniedovich| first1 = Moshe|journal = INFORMS Transactions on Education,|volume = 4(| issue=1) |pages = 48–64.|doi-access = free}}</ref>
 
: ''W''(''n'',''k'') = 1 + min{max(''W''(''n'' &minus; 1, ''x'' &minus; 1), ''W''(''n'',''k'' &minus; ''x'')): ''x'' = 1, 2, ..., ''k'' }
Line 427 ⟶ 460:
But the recurrence relation can in fact be solved, giving <math>f(t,n) = \sum_{i=0}^{n}{ \binom{t}{i} }</math>, which can be computed in <math>O(n)</math> time using the identity <math>\binom{t}{i+1} = \binom{t}{i} \frac{t-i}{i+1}</math> for all <math>i \geq 0</math>.
 
Since <math>f(t,n) \leq f(t+1,n)</math> for all <math>t \geq 0</math>, we can binary search on <math>t</math> to find <math>x</math>, giving an <math>O( n \log k )</math> algorithm.<ref>{{Citation |author=Dean Connable Wills |title=Connections between combinatorics of permutations and algorithms and geometry |url=https://ir.library.oregonstate.edu/xmlui/handle/1957/11929?show=full}}</ref>
<ref>{{Citation |author=Dean Connable Wills |title=Connections between combinatorics of permutations and algorithms and geometry |url=https://ir.library.oregonstate.edu/xmlui/handle/1957/11929?show=full}}</ref>
 
=== Matrix chain multiplication ===
Line 437 ⟶ 469:
This is such a long example that it might be better to make it its own article.-->
 
Matrix chain multiplication is a well-known example that demonstrates utility of dynamic programming. For example, engineering applications often have to multiply a chain of matrices. It is not surprising to find matrices of large dimensions, for example 100×100. Therefore, our task is to multiply matrices {{tmath|A_1, A_2, .... A_n}}. As we know from basic linear algebra, matrixMatrix multiplication is not commutative, but is associative; and we can multiply only two matrices at a time. So, we can multiply this chain of matrices in many different ways, for example:
 
: {{math|((''A''<sub>1</sub> × ''A''<sub>2</sub>) × ''A''<sub>3</sub>) × ... ''A<sub>n</sub>''}}
 
: {{math|''A''<sub>1</sub>×(((''A''<sub>2</sub>×A×''A''<sub>3</sub>)× ... ) × ''A<sub>n</sub>'')}}
 
: {{math|(''A''<sub>1</sub> × ''A''<sub>2</sub>) × (''A''<sub>3</sub> × ... ''A<sub>n</sub>'')}}
 
and so on. There are numerous ways to multiply this chain of matrices. They will all produce the same final result, however they will take more or less time to compute, based on which particular matrices are multiplied. If matrix A has dimensions m×n and matrix B has dimensions n×q, then matrix C=A×B will have dimensions m×q, and will require m*n*q scalar multiplications (using a simplistic [[matrix multiplication algorithm]] for purposes of illustration).
 
For example, let us multiply matrices A, B and C. Let us assume that their dimensions are m×n, n×p, and p×s, respectively. Matrix A×B×C will be of size m×s and can be calculated in two ways shown below:
Line 452 ⟶ 484:
# (A×B)×C This order of matrix multiplication will require mnp + mps scalar calculations.
 
Let us assume that m = 10, n = 100, p = 10 and s = 1000. So, the first way to multiply the chain will require 1,000,000 + 1,000,000 calculations. The second way will require only 10,000 + 100,000 calculations. Obviously, the second way is faster, and we should multiply the matrices using that arrangement of parenthesis.
 
Therefore, our conclusion is that the order of parenthesis matters, and that our task is to find the optimal order of parenthesis.
Line 472 ⟶ 504:
This formula can be coded as shown below, where input parameter "chain" is the chain of matrices, i.e. {{tmath|A_1, A_2, ... A_n}}:
 
'''function''' OptimalMatrixChainParenthesis(chain)
n = length(chain)
'''for''' i = 1, n
m[i,i] = 0 ''// Since it takes no calculations to multiply one matrix''
'''for''' len = 2, n
'''for''' i = 1, n - len + 1
j = i + len -1
m[i,j] = infinity ''// So that the first calculation updates''
'''for''' k = i, j-1
{{nowrap|1=q = m[i, k] + m[k+1, j] + <math>p_{i-1}*p_k*p_j</math>}}
'''if''' q < m[i, j] ''// The new order of parentheses is better than what we had''
m[i, j] = q ''// Update''
s[i, j] = k ''// Record which k to split on, i.e. where to place the parenthesis''
 
So far, we have calculated values for all possible {{math|''m''[''i'', ''j'']}}, the minimum number of calculations to multiply a chain from matrix ''i'' to matrix ''j'', and we have recorded the corresponding "split point"{{math|''s''[''i'', ''j'']}}. For example, if we are multiplying chain {{math|''A''<sub>1</sub>×A×''A''<sub>2</sub>×A×''A''<sub>3</sub>×A×''A''<sub>4</sub>}}, and it turns out that {{math|1=''m''[1, 3] = 100}} and {{math|1=''s''[1, 3] = 2}}, that means that the optimal placement of parenthesis for matrices 1 to 3 is {{tmath|(A_1\times A_2)\times A_3}} and to multiply those matrices will require 100 scalar calculationcalculations.
 
This algorithm will produce "tables" ''m''[, ] and ''s''[, ] that will have entries for all possible values of i and j. The final solution for the entire chain is m[1, n], with corresponding split at s[1, n]. Unraveling the solution will be recursive, starting from the top and continuing until we reach the base case, i.e. multiplication of single matrices.
Line 492 ⟶ 524:
Therefore, the next step is to actually split the chain, i.e. to place the parenthesis where they (optimally) belong. For this purpose we could use the following algorithm:
 
'''function''' PrintOptimalParenthesis(s, i, j)
'''if''' i = j
print "A"i
'''else'''
print "("
PrintOptimalParenthesis(s, i, s[i, j])
PrintOptimalParenthesis(s, s[i, j] + 1, j) ")"
print ")"
 
Of course, this algorithm is not useful for actual multiplication. This algorithm is just a user-friendly way to see what the result looks like.
Line 529 ⟶ 564:
</syntaxhighlight>
 
== History of the name ==
The term ''dynamic programming'' was originally used in the 1940s by [[Richard Bellman]] to describe the process of solving problems where one needs to find the best decisions one after another. By 1953, he refined this to the modern meaning, referring specifically to nesting smaller decision problems inside larger decisions,<ref>Stuart Dreyfus. [https://web.archive.org/web/20050110161049/http://www.wu-wien.ac.at/usr/h99c/h9951826/bellman_dynprog.pdf "Richard Bellman on the birth of Dynamical Programming"].</ref> and the field was thereafter recognized by the [[IEEE]] as a [[systems analysis]] and [[engineering]] topic. Bellman's contribution is remembered in the name of the [[Bellman equation]], a central result of dynamic programming which restates an optimization problem in [[Recursion (computer science)|recursive]] form.
 
Bellman explains the reasoning behind the term ''dynamic programming'' in his autobiography, ''Eye of the Hurricane: An Autobiography'':
 
{{Blockquote
{{Quote
|text=I spent the Fall quarter (of 1950) at [[RAND Corporation|RAND]]. My first task was to find a name for multistage decision processes. An interesting question is, "Where did the name, dynamic programming, come from?" The 1950s were not good years for mathematical research. We had a very interesting gentleman in Washington named [[Charles Erwin Wilson|Wilson]]. He was Secretary of Defense, and he actually had a pathological fear and hatred of the word "research". I’mI'm not using the term lightly; I’mI'm using it precisely. His face would suffuse, he would turn red, and he would get violent if people used the term research in his presence. You can imagine how he felt, then, about the term mathematical. The RAND Corporation was employed by the Air Force, and the Air Force had Wilson as its boss, essentially. Hence, I felt I had to do something to shield Wilson and the Air Force from the fact that I was really doing mathematics inside the RAND Corporation. What title, what name, could I choose? In the first place I was interested in planning, in decision making, in thinking. But planning, is not a good word for various reasons. I decided therefore to use the word "programming". I wanted to get across the idea that this was dynamic, this was multistage, this was time-varying. I thought, let's kill two birds with one stone. Let's take a word that has an absolutely precise meaning, namely dynamic, in the classical physical sense. It also has a very interesting property as an adjective, and that is it's impossible to use the word dynamic in a pejorative sense. Try thinking of some combination that will possibly give it a pejorative meaning. It's impossible. Thus, I thought dynamic programming was a good name. It was something not even a Congressman could object to. So I used it as an umbrella for my activities.
|author=Richard Bellman
|source=''Eye of the Hurricane: An Autobiography'' (1984, page 159)
}}
 
The word ''dynamic'' was chosen by Bellman to capture the time-varying aspect of the problems, and because it sounded impressive.<ref name="Eddy">{{cite journal |last=Eddy |first=S. R. |authorlinkauthor-link=Sean Eddy |title=What is Dynamic Programming? |journal=Nature Biotechnology |volume=22 |issue= 7|pages=909–910 |year=2004 |doi=10.1038/nbt0704-909 |pmid=15229554 |s2cid=5352062 }}</ref> The word ''programming'' referred to the use of the method to find an optimal ''program'', in the sense of a military schedule for training or logistics. This usage is the same as that in the phrases ''[[linear programming]]'' and ''mathematical programming'', a synonym for [[mathematical optimization]].<ref>{{cite book |lastlast1=Nocedal |firstfirst1=J. |last2=Wright |first2=S. J. |title=Numerical Optimization |url=https://archive.org/details/numericaloptimiz00noce_639 |url-access=limited |page=[https://archive.org/details/numericaloptimiz00noce_639/page/n21 9] |publisher=Springer |year=2006 |isbn=9780387303031 }}</ref>
 
The above explanation of the origin of the term ismay lacking.be Asinaccurate: According to Russell and Norvig in their book have written, referring to the above story: "This cannot be strictly true, because his first paper using the term (Bellman, 1952) appeared before Wilson became Secretary of Defense in 1953."<ref>{{cite book |lastlast1=Russell |firstfirst1=S. |last2=Norvig |first2=P. |title=Artificial Intelligence: A Modern Approach |edition=3rd |publisher=Prentice Hall |year=2009 |isbn=978-0-13-207148-2 }}</ref> Also, there is a comment in a speech by [http://a2c2.org/awards/richard-e-bellman-control-heritage-award/2004-00-00t000000/harold-j-kushner [Harold J. Kushner],] wherestated hein remembersa Bellman.speech Quoting Kushner as he speaks of Bellman:that, "On the other hand, when I asked him[Bellman] the same question, he replied that he was trying to upstage [[George Dantzig|Dantzig's]] linear programming by adding dynamic. Perhaps both motivations were true."<ref>{{Cite web |date=2004-07-01 |title=Richard E. Bellman Control Heritage Award |url=http://a2c2.org/awards/richard-e-bellman-control-heritage-award-0 |archive-url=https://web.archive.org/web/20141019015133/http://a2c2.org/awards/richard-e-bellman-control-heritage-award/2004-00-00t000000/harold-j-kushner |archive-date=2014-10-19 |first=Harold J. |last=Kushner |author-link=Harold J. Kushner}}</ref>
 
== Algorithms that use dynamic programming ==
{{unreferenced section|date=May 2013}}
* Recurrent solutions to [[lattice models]] for protein-DNA binding
* [[Backward induction]] as a solution method for finite-horizon [[discrete-time]] dynamic optimization problems
* [[Method of undetermined coefficients]] can be used to solve the [[Bellman equation]] in infinite-horizon, discrete-time, [[discounting|discounted]], [[Time-invariant system|time-invariant]] dynamic optimization problems
* Many [[String (computer science)|string]] algorithms including [[longest common subsequence problem|longest common subsequence]], [[Longest increasing subsequence problem|longest increasing subsequence]], [[Longest common substring problem|longest common substring]], [[Levenshtein distance]] (edit distance)
* Many algorithmic problems on [[undirected graph|graphs]] can be solved efficiently for graphs of bounded [[treewidth]] or bounded [[clique-width]] by using dynamic programming on a [[tree decomposition]] of the graph.
* The [[CYK algorithm|Cocke–Younger–Kasami (CYK) algorithm]] which determines whether and how a given string can be generated by a given [[context-free grammar]]
* [[Word wrap|Knuth's word wrapping algorithm]] that minimizes raggedness when word wrapping text
* The use of [[transposition table]]s and [[refutation table]]s in [[computer chess]]
* The [[Viterbi algorithm]] (used for [[hidden Markov model]]s, and particularly in [[part of speech tagging]])
* The [[Earley algorithm]] (a type of [[chart parser]])
* The [[Needleman–Wunsch algorithm]] and other algorithms used in [[bioinformatics]], including [[sequence alignment]], [[structural alignment]], [[RNA structure|RNA structure prediction]] <ref name="Eddy" />
* [[Floyd–Warshall algorithm|Floyd's all-pairs shortest path algorithm]]
* Optimizing the order for [[chain matrix multiplication]]
* [[Pseudo-polynomial time]] algorithms for the [[subset sum problem|subset sum]], [[Knapsack problem|knapsack]] and [[Partition problem|partition]] problems
* The [[dynamic time warping]] algorithm for computing the global distance between two time series
* The [[Patricia Selinger|Selinger]] (a.k.a. [[IBM System R|System R]]) algorithm for relational database query optimization
* [[De Boor algorithm]] for evaluating B-spline curves
* [[Duckworth–Lewis method]] for resolving the problem when games of cricket are interrupted
* The value iteration method for solving [[Markov decision process]]es
* Some graphic image edge following selection methods such as the "magnet" selection tool in [[Photoshop]]
* Some methods for solving [[interval scheduling]] problems
* Some methods for solving the [[travelling salesman problem]], either exactly (in [[exponential time]]) or approximately (e.g. via the [[bitonic tour]])
* [[Recursive least squares]] method
* [[Beat (music)|Beat]] tracking in [[music information retrieval]]
* Adaptive-critic training strategy for [[artificial neural networks]]
* Stereo algorithms for solving the [[correspondence problem]] used in stereo vision
* [[Seam carving]] (content-aware image resizing)
* The [[Bellman–Ford algorithm]] for finding the shortest distance in a graph
* Some approximate solution methods for the [[linear search problem]]
* Kadane's algorithm for the [[maximum subarray problem]]
*Optimization of electric generation expansion plans in the [https://www-pub.iaea.org/MTCD/publications/PDF/CMS-16.pdf Wein Automatic System Planning (WASP)] package
 
== See also ==
{{Portal|Systems science|Mathematics}}
 
<!-- alphabetical order please [[WP:SEEALSO]] -->
* [[Convexity in economics]]
<!-- please add a short description [[WP:SEEALSO]], via {{subst:AnnotatedListOfLinks}} or {{Annotated link}} -->
* [[Greedy algorithm]]
{{div col|colwidth=30em|small=}}
* [[Non-convexity (economics)]]
* {{Annotated link |Convexity in economics}}
* [[Stochastic programming]]
* {{Annotated link |Greedy algorithm}}
* [[Stochastic dynamic programming]]
* {{Annotated link |Non-convexity (economics)}}
* [[Reinforcement learning]]
* {{Annotated link |Stochastic programming}}
* {{Annotated link |Stochastic dynamic programming}}
* {{Annotated link |Reinforcement learning}}
{{div col end}}
<!-- alphabetical order please [[WP:SEEALSO]] -->
 
== References ==
{{Reflist|30em}}
 
== Further reading ==
*{{citation|last1=Adda|first1=Jerome|last2=Cooper|first2=Russell|year=2003|url=https://mitpress.mit.edu/books/dynamic-economics|title=Dynamic Economics|publisher=MIT Press|isbn=9780262012010}}. An accessible introduction to dynamic programming in economics. [https://sites.google.com/site/coopereconomics/matlab-programs MATLAB code for the book] {{Webarchive|url=https://web.archive.org/web/20201009085820/https://sites.google.com/site/coopereconomics/matlab-programs |date=2020-10-09 }}.
*{{citation|first=Richard|last=Bellman|authorlinkauthor-link=Richard Bellman|title=The theory of dynamic programming| journal=[[Bulletin of the American Mathematical Society]] |year=1954| volume=60| pages=503–516|doi=10.1090/S0002-9904-1954-09848-8|mr=0067459|issue=6|doi-access=free}}. Includes an extensive bibliography of the literature in the area, up to the year 1954.
*{{citation|first=Richard|last=Bellman|authorlinkauthor-link=Richard Bellman|year=1957|title=Dynamic Programming| publisher=Princeton University Press}}. Dover paperback edition (2003), {{isbn|0-486-42809-5}}.
*{{citation|last1=Cormen|first1=Thomas H.|author1-link=Thomas H. Cormen|last2=Leiserson| first2=Charles E.| author2-link=Charles E. Leiserson|last3=Rivest|first3=Ronald L.|author3-link=Ronald L. Rivest|last4=Stein|first4=Clifford|author4-link=Clifford Stein|year=2001| title=Introduction to Algorithms|edition=2nd|publisher=MIT Press & McGraw–Hill|isbn=978-0-262-03293-3|title-link=Introduction to Algorithms}}. Especially pp.&nbsp;323–69.
*{{citation|first1=Stuart E.|last1=Dreyfus|first2=Averill M.|last2=Law|year=1977|title=The Art and Theory of Dynamic Programming|publisher=Academic Press|isbn=978-0-12-221860-6}}.
*{{citation| last1=Giegerich| first1=R.|last2=Meyer| first2=C.|last3=Steffen| first3=P.| year=2004| url=http://bibiserv.techfak.uni-bielefeld.de/adp/ps/GIE-MEY-STE-2004.pdf|title=A Discipline of Dynamic Programming over Sequence Data|journal=Science of Computer Programming|volume=51|pages=215–263| issue=3|doi=10.1016/j.scico.2003.12.005|doi-access=free}}.
*{{citation|first=Sean| last=Meyn| url=https://netfiles.uiuc.edu/meyn/www/spm_files/CTCN/CTCN.html|title=Control Techniques for Complex Networks| publisher=Cambridge University Press| year=2007|isbn=978-0-521-88441-9|url-status=dead|archiveurl archive-url=https://web.archive.org/web/20100619011046/https://netfiles.uiuc.edu/meyn/www/spm_files/CTCN/CTCN.html|archivedatearchive-date=2010-06-19|df=}}.
*{{cite journal | last1 = Sritharan | first1 = S. S. | year = 1991 | title = Dynamic Programming of the Navier-Stokes Equations | url = | journal = Systems and Control Letters | volume = 16 | issue = 4| pages = 299–307 | doi=10.1016/0167-6911(91)90020-f}}
*{{citation|last1=Stokey|first1=Nancy|author1-link=Nancy Stokey|last2=Lucas|first2=Robert E.| author2-link=Robert E. Lucas|last3=Prescott|first3=Edward|author3-link=Edward Prescott|year=1989| title=Recursive Methods in Economic Dynamics|publisher=Harvard Univ. Press|isbn=978-0-674-75096-8}}.
 
== External links ==
{{external cleanup|date=March 2016}}
* [https://www.interviewbit.com/courses/programming/topics/dynamic-programming/ Dynamic Programming Problems]
* [http://apmonitor.com/do Dynamic Optimization Online Course]
* [http://mat.gsia.cmu.edu/classes/dynamic/dynamic.html A Tutorial on Dynamic programming]
* [https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-046j-introduction-to-algorithms-sma-5503-fall-2005/video-lectures/ MIT course on algorithms] – Includes a video lecture on DP along with lecture notes, see lecture 15.
* [http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Dynamic More DP Notes]
* King, Ian, 2002 (1987), "[http://researchspace.auckland.ac.nz/bitstream/handle/2292/190/230.pdf A Simple Introduction to Dynamic Programming in Macroeconomic Models.]" An introduction to dynamic programming as an important tool in economic theory.
* [http://www.topcoder.com/tc?module=Static&d1=tutorials&d2=dynProg Dynamic Programming: from novice to advanced] A TopCoder.com article by Dumitru on Dynamic Programming
* [https://bibiserv.cebitec.uni-bielefeld.de/adp/welcome.html Algebraic Dynamic Programming] – a formalized framework for dynamic programming, including an [https://bibiserv.cebitec.uni-bielefeld.de/cgi-bin/dpcourse entry-level course] to DP, University of Bielefeld
* Dreyfus, Stuart, "[http://www.cas.mcmaster.ca/~se3c03/journal_papers/dy_birth.pdf Richard Bellman on the birth of Dynamic Programming.]"
* [https://web.archive.org/web/20080626183359/http://www.avatar.se/lectures/molbioinfo2001/dynprog/dynamic.html Dynamic programming tutorial]
* [http://www.cambridge.org/resources/0521882672/7934_kaeslin_dynpro_new.pdf A Gentle Introduction to Dynamic Programming and the Viterbi Algorithm]
* Tabled Prolog [http://www.probp.com BProlog] and [http://xsb.sourceforge.net/ XSB]
* [https://ifors.ms.unimelb.edu.au/tutorial/ IFORS online interactive dynamic programming modules] including, shortest path, traveling salesman, knapsack, false coin, egg dropping, bridge and torch, replacement, chained matrix products, and critical path problem.
 
 
{{optimization algorithms|combinatorial|state=expanded}}
 
 
{{Optimization algorithms|combinatorial|state=expanded}}
{{Parsers}}
{{Algorithmic paradigms}}
 
{{Authority control}}