On t Talk to Me or My Subproblem Every Again

Problem optimization method

Effigy ane. 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 2 vertices it connects (among other paths, not shown, sharing the aforementioned two vertices); the bold line is the overall shortest path from start to goal.

Dynamic programming is both a mathematical optimization method and a computer programming method. The method was developed past 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 recursive manner. While some decision problems cannot be taken apart this way, decisions that span several points in time do ofttimes break apart recursively. Likewise, in calculator science, if a problem tin can be solved optimally past breaking it into sub-problems and and then recursively finding the optimal solutions to the sub-bug, then it is said to take optimal substructure.

If sub-issues tin be nested recursively inside larger problems, then that dynamic programming methods are applicable, then in that location is a relation betwixt the value of the larger problem and the values of the sub-issues.[i] In the optimization literature this human relationship is chosen the Bellman equation.

Overview [edit]

Mathematical optimization [edit]

In terms of mathematical optimization, dynamic programming commonly refers to simplifying a determination past breaking it down into a sequence of decision steps over fourth dimension. This is done by defining a sequence of value functions V ane, V ii, ..., Five n taking y as an argument representing the state of the system at times i from 1 to northward. The definition of V n (y) is the value obtained in state y at the last fourth dimension n. The values V i at earlier times i =n −1,n − ii, ..., 2, 1 tin be institute by working backwards, using a recursive relationship called the Bellman equation. For i = 2, ...,n, V i−i at any state y is calculated from V i by maximizing a unproblematic function (commonly the sum) of the gain from a decision at fourth dimension i − 1 and the function V i at the new land of the organization if this determination is made. Since 5 i has already been calculated for the needed states, the above functioning yields V i−i for those states. Finally, V 1 at the initial state of the system is the value of the optimal solution. The optimal values of the conclusion variables tin be recovered, one by ane, by tracking back the calculations already performed.

Control theory [edit]

In control theory, a typical trouble is to find an admissible control u {\displaystyle \mathbf {u} ^{\ast }} which causes the organization x ˙ ( t ) = g ( ten ( t ) , u ( t ) , t ) {\displaystyle {\dot {\mathbf {x} }}(t)=\mathbf {g} \left(\mathbf {x} (t),\mathbf {u} (t),t\correct)} to follow an admissible trajectory x {\displaystyle \mathbf {x} ^{\ast }} on a continuous fourth dimension interval t 0 t t 1 {\displaystyle t_{0}\leq t\leq t_{i}} that minimizes a cost function

J = b ( x ( t i ) , t 1 ) + t 0 t 1 f ( x ( t ) , u ( t ) , t ) d t {\displaystyle J=b\left(\mathbf {x} (t_{1}),t_{ane}\right)+\int _{t_{0}}^{t_{i}}f\left(\mathbf {x} (t),\mathbf {u} (t),t\correct)\mathrm {d} t}

The solution to this trouble is an optimal control law or policy u = h ( x ( t ) , t ) {\displaystyle \mathbf {u} ^{\ast }=h(\mathbf {10} (t),t)} , which produces an optimal trajectory x {\displaystyle \mathbf {x} ^{\ast }} and a cost-to-go function J {\displaystyle J^{\ast }} . The latter obeys the fundamental equation of dynamic programming:

J t = min u { f ( x ( t ) , u ( t ) , t ) + J x T g ( x ( t ) , u ( t ) , t ) } {\displaystyle -J_{t}^{\ast }=\min _{\mathbf {u} }\left\{f\left(\mathbf {x} (t),\mathbf {u} (t),t\correct)+J_{x}^{\ast {\mathsf {T}}}\mathbf {g} \left(\mathbf {x} (t),\mathbf {u} (t),t\right)\right\}}

a partial differential equation known as the Hamilton–Jacobi–Bellman equation, in which J x = J x = [ J x 1 J ten 2 J x n ] T {\displaystyle J_{x}^{\ast }={\frac {\partial J^{\ast }}{\fractional \mathbf {x} }}=\left[{\frac {\partial J^{\ast }}{\partial x_{one}}}~~~~{\frac {\partial J^{\ast }}{\partial x_{2}}}~~~~\dots ~~~~{\frac {\fractional J^{\ast }}{\partial x_{north}}}\right]^{\mathsf {T}}} and J t = J t {\displaystyle J_{t}^{\ast }={\frac {\partial J^{\ast }}{\partial t}}} . 1 finds that minimizing u {\displaystyle \mathbf {u} } in terms of t {\displaystyle t} , x {\displaystyle \mathbf {x} } , and the unknown function J ten {\displaystyle J_{x}^{\ast }} so substitutes the event into the Hamilton–Jacobi–Bellman equation to get the partial differential equation to exist solved with boundary condition J ( t 1 ) = b ( x ( t ane ) , t 1 ) {\displaystyle J\left(t_{1}\right)=b\left(\mathbf {x} (t_{1}),t_{1}\right)} .[2] In do, this generally requires numerical techniques for some discrete approximation to the exact optimization human relationship.

Alternatively, the continuous procedure tin be approximated past a detached organisation, which leads to a following recurrence relation analog to the Hamilton–Jacobi–Bellman equation:

J k ( x northward 1000 ) = min u n grand { f ^ ( ten n k , u n chiliad ) + J yard 1 ( g ^ ( x n k , u north 1000 ) ) } {\displaystyle J_{k}^{\ast }\left(\mathbf {x} _{north-thousand}\correct)=\min _{\mathbf {u} _{due north-g}}\left\{{\hat {f}}\left(\mathbf {ten} _{n-k},\mathbf {u} _{n-k}\right)+J_{k-1}^{\ast }\left({\hat {\mathbf {grand} }}\left(\mathbf {x} _{n-k},\mathbf {u} _{northward-k}\right)\right)\right\}}

at the g {\displaystyle m} -thursday stage of north {\displaystyle northward} equally spaced detached time intervals, and where f ^ {\displaystyle {\hat {f}}} and thou ^ {\displaystyle {\hat {\mathbf {g} }}} denote detached approximations to f {\displaystyle f} and g {\displaystyle \mathbf {g} } . This functional equation is known equally the Bellman equation, which can exist solved for an exact solution of the discrete approximation of the optimization equation.[iii]

Example from economics: Ramsey'south problem of optimal saving [edit]

In economics, the objective is generally to maximize (rather than minimize) some dynamic social welfare function. In Ramsey's problem, this office relates amounts of consumption to levels of utility. Loosely speaking, the planner faces the trade-off betwixt contemporaneous consumption and future consumption (via investment in capital stock that is used in production), known as intertemporal choice. Future consumption is discounted at a constant rate β ( 0 , 1 ) {\displaystyle \beta \in (0,1)} . A discrete approximation to the transition equation of upper-case letter is given by

k t + 1 = g ^ ( k t , c t ) = f ( k t ) c t {\displaystyle k_{t+one}={\hat {g}}\left(k_{t},c_{t}\right)=f(k_{t})-c_{t}}

where c {\displaystyle c} is consumption, g {\displaystyle k} is capital, and f {\displaystyle f} is a production function satisfying the Inada conditions. An initial capital letter stock k 0 > 0 {\displaystyle k_{0}>0} is assumed.

Let c t {\displaystyle c_{t}} be consumption in flow t, and assume consumption yields utility u ( c t ) = ln ( c t ) {\displaystyle u(c_{t})=\ln(c_{t})} equally long as the consumer lives. Assume the consumer is impatient, and so that he discounts futurity utility by a gene b each period, where 0 < b < 1 {\displaystyle 0<b<1} 0<b<1 . Let grand t {\displaystyle k_{t}} exist capital in period t. Assume initial majuscule is a given corporeality k 0 > 0 {\displaystyle k_{0}>0} , and suppose that this period's capital and consumption determine next menstruum's majuscule as 1000 t + 1 = A m t a c t {\displaystyle k_{t+one}=Ak_{t}^{a}-c_{t}} , where A is a positive constant and 0 < a < 1 {\displaystyle 0<a<1} 0<a<1 . Assume capital cannot exist negative. Then the consumer's decision problem can exist written as follows:

max t = 0 T b t ln ( c t ) {\displaystyle \max \sum _{t=0}^{T}b^{t}\ln(c_{t})} subject to m t + one = A g t a c t 0 {\displaystyle k_{t+1}=Ak_{t}^{a}-c_{t}\geq 0} for all t = 0 , one , 2 , , T {\displaystyle t=0,1,2,\ldots ,T}

Written this way, the problem looks complicated, considering information technology involves solving for all the choice variables c 0 , c ane , c 2 , , c T {\displaystyle c_{0},c_{1},c_{2},\ldots ,c_{T}} . (The capital m 0 {\displaystyle k_{0}} is not a option variable—the consumer's initial upper-case letter is taken as given.)

The dynamic programming approach to solve this problem involves breaking it apart into a sequence of smaller decisions. To practise so, we define a sequence of value functions Five t ( k ) {\displaystyle V_{t}(k)} , for t = 0 , i , 2 , , T , T + 1 {\displaystyle t=0,ane,2,\ldots ,T,T+one} which represent the value of having whatsoever amount of upper-case letter k at each time t. There is (by assumption) no utility from having uppercase afterwards death, Five T + i ( g ) = 0 {\displaystyle V_{T+1}(yard)=0} .

The value of any quantity of capital at any previous time can be calculated past backward induction using the Bellman equation. In this problem, for each t = 0 , 1 , ii , , T {\displaystyle t=0,1,2,\ldots ,T} , the Bellman equation is

V t ( yard t ) = max ( ln ( c t ) + b V t + 1 ( g t + 1 ) ) {\displaystyle V_{t}(k_{t})\,=\,\max \left(\ln(c_{t})+bV_{t+ane}(k_{t+one})\right)} field of study to k t + ane = A k t a c t 0 {\displaystyle k_{t+1}=Ak_{t}^{a}-c_{t}\geq 0}

This problem is much simpler than the one nosotros wrote down earlier, because it involves only two determination variables, c t {\displaystyle c_{t}} and grand t + 1 {\displaystyle k_{t+i}} . Intuitively, instead of choosing his whole lifetime programme at birth, the consumer can take things ane step at a time. At fourth dimension t, his current upper-case letter yard t {\displaystyle k_{t}} is given, and he simply needs to choose electric current consumption c t {\displaystyle c_{t}} and saving one thousand t + 1 {\displaystyle k_{t+i}} .

To actually solve this problem, we work backwards. For simplicity, the current level of uppercase is denoted every bit k. V T + one ( k ) {\displaystyle V_{T+i}(k)} is already known, then using the Bellman equation in one case we tin calculate V T ( one thousand ) {\displaystyle V_{T}(k)} , and so on until we get to V 0 ( k ) {\displaystyle V_{0}(thousand)} , which is the value of the initial determination problem for the whole lifetime. In other words, once we know V T j + ane ( k ) {\displaystyle V_{T-j+1}(k)} , we can summate V T j ( k ) {\displaystyle V_{T-j}(k)} , which is the maximum of ln ( c T j ) + b V T j + ane ( A 1000 a c T j ) {\displaystyle \ln(c_{T-j})+bV_{T-j+ane}(Ak^{a}-c_{T-j})} , where c T j {\displaystyle c_{T-j}} is the choice variable and A k a c T j 0 {\displaystyle Ak^{a}-c_{T-j}\geq 0} .

Working backwards, information technology can be shown that the value function at time t = T j {\displaystyle t=T-j} is

Five T j ( m ) = a i = 0 j a i b i ln thousand + v T j {\displaystyle V_{T-j}(m)\,=\,a\sum _{i=0}^{j}a^{i}b^{i}\ln thousand+v_{T-j}}

where each five T j {\displaystyle v_{T-j}} is a constant, and the optimal amount to swallow at time t = T j {\displaystyle t=T-j} is

c T j ( k ) = 1 i = 0 j a i b i A chiliad a {\displaystyle c_{T-j}(m)\,=\,{\frac {i}{\sum _{i=0}^{j}a^{i}b^{i}}}Ak^{a}}

which can be simplified to

c T ( k ) = A k a c T 1 ( one thousand ) = A k a 1 + a b c T 2 ( k ) = A thou a 1 + a b + a ii b ii c two ( grand ) = A k a 1 + a b + a 2 b 2 + + a T 2 b T ii c 1 ( k ) = A k a 1 + a b + a two b ii + + a T 2 b T ii + a T 1 b T 1 c 0 ( g ) = A yard a 1 + a b + a 2 b two + + a T 2 b T ii + a T ane b T 1 + a T b T {\displaystyle {\begin{aligned}c_{T}(k)&=Ak^{a}\\c_{T-1}(k)&={\frac {Ak^{a}}{1+ab}}\\c_{T-two}(k)&={\frac {Ak^{a}}{1+ab+a^{ii}b^{2}}}\\&\dots \\c_{two}(k)&={\frac {Ak^{a}}{ane+ab+a^{2}b^{ii}+\ldots +a^{T-2}b^{T-2}}}\\c_{1}(1000)&={\frac {Ak^{a}}{1+ab+a^{2}b^{two}+\ldots +a^{T-2}b^{T-2}+a^{T-1}b^{T-ane}}}\\c_{0}(k)&={\frac {Ak^{a}}{one+ab+a^{2}b^{two}+\ldots +a^{T-two}b^{T-2}+a^{T-one}b^{T-1}+a^{T}b^{T}}}\stop{aligned}}}

We run across that it is optimal to consume a larger fraction of current wealth as one gets older, finally consuming all remaining wealth in menstruum T, the concluding period of life.

Estimator programming [edit]

In that location are two central attributes that a problem must take in order for dynamic programming to exist applicative: optimal substructure and overlapping sub-problems. If a problem tin be solved past combining optimal solutions to not-overlapping sub-problems, the strategy is called "divide and conquer" instead.[one] This is why merge sort and quick sort are not classified as dynamic programming problems.

Optimal substructure means that the solution to a given optimization trouble can exist obtained by the combination of optimal solutions to its sub-issues. Such optimal substructures are commonly described by means of recursion. For example, given a graph One thousand=(V,East), the shortest path p from a vertex u to a vertex v exhibits optimal substructure: accept any intermediate vertex due west on this shortest path p. If p is truly the shortest path, then it tin can exist split into sub-paths p1 from u to west and p2 from w to v such that these, in turn, are indeed the shortest paths between the corresponding vertices (past the simple cutting-and-paste statement 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-issues must be small, that is, any recursive algorithm solving the problem should solve the aforementioned sub-problems over and over, rather than generating new sub-problems. For example, consider the recursive formulation for generating the Fibonacci series: F i = F i−1 + F i−2, with base of operations instance F 1 =F 2 = 1. Then F 43 =F 42 +F 41, and F 42 =F 41 +F 40. Now F 41 is being solved in the recursive sub-trees of both F 43 too every bit F 42. Even though the total number of sub-problems is actually small (only 43 of them), we cease up solving the aforementioned problems over and over if nosotros adopt a naive recursive solution such as this. Dynamic programming takes account of this fact and solves each sub-trouble only once.

Figure 2. The subproblem graph for the Fibonacci sequence. The fact that it is not a tree indicates overlapping subproblems.

This can be achieved in either of 2 means:[ citation needed ]

  • Meridian-down approach: This is the straight autumn-out of the recursive conception of whatever problem. If the solution to whatsoever problem tin can be formulated recursively using the solution to its sub-issues, and if its sub-problems are overlapping, and then ane tin can easily memoize or store the solutions to the sub-problems in a table. Whenever we try to solve a new sub-trouble, we showtime bank check the table to see if it is already solved. If a solution has been recorded, nosotros can utilize information technology directly, otherwise we solve the sub-problem and add its solution to the table.
  • Lesser-up arroyo: Once we formulate the solution to a problem recursively every bit in terms of its sub-issues, nosotros can endeavour reformulating the problem in a lesser-upward mode: try solving the sub-problems first and use their solutions to build-on and make it at solutions to bigger sub-issues. This is too usually done in a tabular course 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 41 and F xl, nosotros can directly calculate the value of F 42.

Some programming languages can automatically memoize the result of a function phone call with a particular set of arguments, in social club to speed up call-by-proper noun evaluation (this mechanism is referred to as call-by-need). Some languages make information technology possible portably (e.chiliad. Scheme, Common Lisp, Perl or D). Some languages have automatic memoization congenital in, such every bit tabled Prolog and J, which supports memoization with the M. adverb.[4] In any case, this is only possible for a referentially transparent role. Memoization is too encountered as an easily accessible design blueprint within term-rewrite based languages such as Wolfram Language.

Bioinformatics [edit]

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 adult in the 1970s independently by Charles DeLisi in USA[v] and Georgii Gurskii and Alexander Zasedatelev in USSR.[six] Recently these algorithms accept go very popular in bioinformatics and computational biology, particularly in the studies of nucleosome positioning and transcription factor bounden.

Examples: computer algorithms [edit]

Dijkstra's algorithm for the shortest path trouble [edit]

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.[7] [8] [9]

In fact, Dijkstra's explanation of the logic behind the algorithm,[10] namely

Problem 2. Find the path of minimum full length between two given nodes P {\displaystyle P} and Q {\displaystyle Q} .

We use the fact that, if R {\displaystyle R} is a node on the minimal path from P {\displaystyle P} to Q {\displaystyle Q} , knowledge of the latter implies the knowledge of the minimal path from P {\displaystyle P} to R {\displaystyle R} .

is a paraphrasing of Bellman's famous Principle of Optimality in the context of the shortest path problem.

Fibonacci sequence [edit]

Using dynamic programming in the calculation of the nth fellow member of the Fibonacci sequence improves its functioning greatly. Here is a naïve implementation, based directly on the mathematical definition:

          function          fib(n)          if          north <= 1          return          n          return          fib(n − ane) + fib(n − ii)        

Notice that if we call, say, fib(v), we produce a call tree that calls the function on the same value many different times:

  1. fib(5)
  2. fib(4) + fib(3)
  3. (fib(3) + fib(two)) + (fib(2) + fib(1))
  4. ((fib(ii) + fib(1)) + (fib(1) + fib(0))) + ((fib(1) + fib(0)) + fib(1))
  5. (((fib(1) + fib(0)) + fib(1)) + (fib(1) + fib(0))) + ((fib(1) + fib(0)) + fib(1))

In particular, fib(ii) was calculated 3 times from scratch. In larger examples, many more than values of fib, or subproblems, are recalculated, leading to an exponential time algorithm.

Now, suppose we have a simple map object, 1000, which maps each value of fib that has already been calculated to its result, and we modify our function to use information technology and update it. The resulting function requires just O(north) fourth dimension instead of exponential time (but requires O(due north) infinite):

          var          m :=                      map          (0 → 0, i → 1)          function          fib(n)          if            key                    n          is not in            map                    m          thousand[due north] := fib(n − 1) + fib(due north − 2)          return          k[north]        

This technique of saving values that have already been calculated is called memoization; this is the top-downwardly approach, since we first break the problem into subproblems and then calculate and store values.

In the bottom-up arroyo, we calculate the smaller values of fib first, and then build larger values from them. This method also uses O(n) time since it contains a loop that repeats n − one times, but information technology only takes abiding (O(1)) space, in dissimilarity to the tiptop-downward approach which requires O(n) infinite to store the map.

          office          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          render          currentFib        

In both examples, we simply summate fib(two) one time, and then employ it to calculate both fib(four) and fib(3), instead of computing it every fourth dimension either of them is evaluated.

The above method really takes Ω ( north two ) {\displaystyle \Omega (n^{2})} fourth dimension for big n because addition of two integers with Ω ( northward ) {\displaystyle \Omega (due north)} $.25 each takes Ω ( due north ) {\displaystyle \Omega (northward)} time. (The n th fibonacci number has Ω ( n ) {\displaystyle \Omega (n)} bits.) Besides, at that place is a airtight form for the Fibonacci sequence, known equally Binet's formula, from which the n {\displaystyle northward} -th term can be computed in approximately O ( north ( log northward ) 2 ) {\displaystyle O(northward(\log n)^{2})} time, which is more than efficient than the above dynamic programming technique. However, the unproblematic recurrence directly gives the matrix form that leads to an approximately O ( n log n ) {\displaystyle O(n\log n)} algorithm by fast matrix exponentiation.

A type of balanced 0–i matrix [edit]

Consider the trouble of assigning values, either zero or 1, to the positions of an n × north matrix, with n even, and so that each row and each column contains exactly north / two zeros and n / 2 ones. We enquire how many different assignments there are for a given n {\displaystyle n} . For case, when n = 4, five possible solutions are

[ 0 1 0 1 ane 0 i 0 0 ane 0 1 1 0 i 0 ]  and [ 0 0 ane 1 0 0 1 ane 1 1 0 0 1 1 0 0 ]  and [ ane 1 0 0 0 0 1 ane one 1 0 0 0 0 ane one ]  and [ i 0 0 1 0 1 1 0 0 1 i 0 i 0 0 one ]  and [ one ane 0 0 i 1 0 0 0 0 1 1 0 0 i 1 ] . {\displaystyle {\begin{bmatrix}0&1&0&ane\\1&0&1&0\\0&1&0&1\\one&0&i&0\end{bmatrix}}{\text{ and }}{\brainstorm{bmatrix}0&0&one&1\\0&0&1&ane\\ane&ane&0&0\\ane&i&0&0\stop{bmatrix}}{\text{ and }}{\begin{bmatrix}i&1&0&0\\0&0&1&1\\1&1&0&0\\0&0&i&1\end{bmatrix}}{\text{ and }}{\brainstorm{bmatrix}1&0&0&i\\0&one&ane&0\\0&one&1&0\\one&0&0&ane\stop{bmatrix}}{\text{ and }}{\begin{bmatrix}ane&one&0&0\\1&one&0&0\\0&0&1&1\\0&0&1&ane\finish{bmatrix}}.}

There are at to the lowest degree three possible approaches: beast forcefulness, backtracking, and dynamic programming.

Brute forcefulness consists of checking all assignments of zeros and ones and counting those that have balanced rows and columns ( n / 2 zeros and n / ii ones). As in that location are 2 n 2 {\displaystyle 2^{n^{2}}} possible assignments and ( north n / 2 ) north {\displaystyle {\tbinom {due north}{n/ii}}^{n}} sensible assignments, this strategy is non practical except maybe up to due north = half-dozen {\displaystyle northward=half dozen} .

Backtracking for this problem consists of choosing some gild 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 n / ii. While more than sophisticated than brute force, this arroyo volition visit every solution once, making it impractical for n larger than 6, since the number of solutions is already 116,963,796,250 for due north  = eight, every bit we shall run into.

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 near the remaining rows, in gild to exist able to accurately count the solutions obtained for each offset row value? We consider k × due north boards, where 1 ≤ kn , whose k {\displaystyle k} rows comprise n / 2 {\displaystyle due north/ii} zeros and northward / 2 {\displaystyle northward/2} ones. The function f to which memoization is applied maps vectors of n pairs of integers to the number of admissible boards (solutions). At that place is one pair for each column, and its 2 components indicate respectively the number of zeros and ones that have all the same to be placed in that column. We seek the value of f ( ( northward / 2 , due north / ii ) , ( n / ii , n / 2 ) , ( n / two , n / 2 ) ) {\displaystyle f((n/2,northward/2),(due north/ii,northward/2),\ldots (n/two,due north/2))} ( n {\displaystyle n} arguments or one vector of n {\displaystyle n} elements). The process of subproblem cosmos involves iterating over every one of ( northward n / ii ) {\displaystyle {\tbinom {n}{n/two}}} possible assignments for the top row of the board, and going through every cavalcade, subtracting one from the appropriate element of the pair for that column, depending on whether the assignment for the peak row contained a cypher 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 take an assignment for the top row of the k × n board and recursively compute the number of solutions to the remaining (k − 1) × n board, adding the numbers of solutions for every open-door assignment of the top row and returning the sum, which is beingness memoized. The base case is the piffling subproblem, which occurs for a i × n board. The number of solutions for this board is either zero or one, depending on whether the vector is a permutation of n / ii ( 0 , i ) {\displaystyle (0,1)} and n / 2 ( 1 , 0 ) {\displaystyle (one,0)} pairs or not.

For example, in the first two boards shown above the sequences of vectors would be

((two, ii) (2, 2) (2, 2) (2, 2))       ((ii, ii) (2, 2) (2, two) (2, ii))     k = 4   0      ane      0      1              0      0      1      i  ((ane, 2) (two, 1) (one, two) (two, 1))       ((one, 2) (1, 2) (2, one) (ii, 1))     thousand = 3   1      0      1      0              0      0      1      1  ((1, 1) (1, one) (one, 1) (1, 1))       ((0, 2) (0, 2) (ii, 0) (2, 0))     k = 2   0      1      0      1              ane      1      0      0  ((0, 1) (1, 0) (0, 1) (1, 0))       ((0, 1) (0, 1) (1, 0) (1, 0))     1000 = i   ane      0      1      0              ane      one      0      0  ((0, 0) (0, 0) (0, 0) (0, 0))       ((0, 0) (0, 0), (0, 0) (0, 0))        

The number of solutions (sequence A058527 in the OEIS) is

1 , ii , ninety , 297200 , 116963796250 , 6736218287430460752 , {\displaystyle 1,\,two,\,90,\,297200,\,116963796250,\,6736218287430460752,\ldots }

Links to the MAPLE implementation of the dynamic programming arroyo may be constitute among the external links.

Checkerboard [edit]

Consider a checkerboard with n × n squares and a toll part c(i, j) which returns a cost associated with foursquare (i,j) ( i being the row, j being the column). For instance (on a 5 × five checkerboard),

v 6 seven iv seven 8
iv 7 vi ane 1 iv
3 3 v 7 8 2
ii 6 7 0
one *v*
i 2 iii 4 v

Thus c(1, three) = 5

Let the states say there was a checker that could start at whatsoever square on the first rank (i.e., row) and you wanted to know the shortest path (the sum of the minimum costs at each visited rank) to get to the concluding rank; assuming the checker could motion merely diagonally left forward, diagonally right forward, or direct forrad. That is, a checker on (1,iii) can move to (2,two), (2,3) or (2,iv).

5
iv
iii
2 x ten x
1 o
1 2 three four 5

This problem exhibits optimal substructure. That is, the solution to the entire problem relies on solutions to subproblems. Let us define a function q(i, j) as

q(i, j) = the minimum cost to reach square (i, j).

Starting at rank northward and descending to rank i, we compute the value of this office for all the squares at each successive rank. Picking the square that holds the minimum value at each rank gives u.s.a. the shortest path betwixt rank n and rank 1.

The function q(i, j) is equal to the minimum cost to get to whatsoever of the three squares below it (since those are the merely squares that can reach it) plus c(i, j). For example:

five
4 A
3 B C D
2
one
i ii iii iv 5
q ( A ) = min ( q ( B ) , q ( C ) , q ( D ) ) + c ( A ) {\displaystyle q(A)=\min(q(B),q(C),q(D))+c(A)\,}

Now, let u.s.a. define q(i, j) in somewhat more general terms:

q ( i , j ) = { j < 1  or j > n c ( i , j ) i = ane min ( q ( i ane , j ane ) , q ( i one , j ) , q ( i one , j + 1 ) ) + c ( i , j ) otherwise. {\displaystyle q(i,j)={\begin{cases}\infty &j<ane{\text{ or }}j>n\\c(i,j)&i=1\\\min(q(i-one,j-1),q(i-1,j),q(i-1,j+one))+c(i,j)&{\text{otherwise.}}\end{cases}}}

The commencement line of this equation deals with a board modeled as squares indexed on ane at the lowest leap and due north at the highest bound. The 2d line specifies what happens at the first rank; providing a base of operations instance. The tertiary line, the recursion, is the important part. It represents the A,B,C,D terms in the example. From this definition we tin derive straightforward recursive lawmaking for q(i, j). In the following pseudocode, n is the size of the board, c(i, j) is the cost function, and min() returns the minimum of a number of values:

          office          minCost(i, j)          if          j < 1          or          j > n          return          infinity          else if          i = 1          return          c(i, j)          else          render          min( minCost(i-ane, j-1), minCost(i-1, j), minCost(i-1, j+1) ) + c(i, j)        

This function just computes the path toll, not the actual path. We discuss the bodily path below. This, like the Fibonacci-numbers example, is horribly slow considering information technology too exhibits the overlapping sub-issues attribute. That is, it recomputes the aforementioned path costs over and over. However, we can compute information technology much faster in a bottom-up fashion if we store path costs in a two-dimensional array q[i, j] rather than using a office. This avoids recomputation; all the values needed for array q[i, j] are computed alee of time only once. Precomputed values for (i,j) are just looked upwards whenever needed.

We also need to know what the actual shortest path is. To do this, we use another array p[i, j]; a predecessor array. This array records the path to any foursquare south. The predecessor of southward is modeled as an first relative to the index (in q[i, j]) of the precomputed path cost of s. To reconstruct the consummate path, we lookup the predecessor of southward, and then the predecessor of that foursquare, then the predecessor of that square, and so on recursively, until nosotros accomplish the starting square. Consider the following pseudocode:

          function          computeShortestPathArrays()          for          ten          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          due north          for          x          from          ane          to          north             m := min(q[y-ane, x-one], q[y-1, x], q[y-1, x+1])             q[y, 10] := m + c(y, ten)          if          m = q[y-1, ten-i]                 p[y, x] := -ane          else if          m = q[y-1, x]                 p[y, x] :=  0          else          p[y, x] :=  1        

Now the rest is a uncomplicated affair 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] < min             minIndex := i             min := q[n, i]     printPath(northward, minIndex)        
          function          printPath(y, x)          print(x)          print("<-")          if          y = two          print(x + p[y, x])          else          printPath(y-1, ten + p[y, x])        

Sequence alignment [edit]

In genetics, sequence alignment is an of import application where dynamic programming is essential.[11] Typically, the problem consists of transforming ane sequence into some other using edit operations that replace, insert, or remove an element. Each operation has an associated cost, and the goal is to find the sequence of edits with the lowest total cost.

The problem can exist stated naturally as a recursion, a sequence A is optimally edited into a sequence B past either:

  1. inserting the starting time character of B, and performing an optimal alignment of A and the tail of B
  2. deleting the first grapheme of A, and performing the optimal alignment of the tail of A and B
  3. replacing the first character of A with the first character of B, and performing optimal alignments of the tails of A and B.

The fractional alignments can be tabulated in a matrix, where prison cell (i,j) contains the cost of the optimal alignment of A[i..i] to B[1..j]. The cost in cell (i,j) tin can exist calculated by adding the cost of the relevant operations to the cost of its neighboring cells, and selecting the optimum.

Different variants exist, see Smith–Waterman algorithm and Needleman–Wunsch algorithm.

Tower of Hanoi puzzle [edit]

A model set up of the Towers of Hanoi (with eight disks)

An animated solution of the Tower of Hanoi puzzle for T(iv,iii).

The Belfry of Hanoi or Towers of Hanoi is a mathematical game or puzzle. It consists of iii rods, and a number of disks of different sizes which tin 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 tiptop, thus making a conical shape.

The objective of the puzzle is to movement the unabridged stack to another rod, obeying the following rules:

  • Only one disk may be moved at a time.
  • Each move consists of taking the upper disk from ane of the rods and sliding it onto another rod, on top of the other disks that may already be present on that rod.
  • No disk may be placed on top of a smaller disk.

The dynamic programming solution consists of solving the functional equation

S(n,h,t) = S(n-one,h, not(h,t)) ; S(one,h,t) ; Southward(n-1,non(h,t),t)

where n denotes the number of disks to be moved, h denotes the abode rod, t denotes the target rod, not(h,t) denotes the third rod (neither h nor t), ";" denotes chain, and

S(n, h, t) := solution to a problem consisting of north disks that are to be moved from rod h to rod t.

For north=i the problem is trivial, namely Due south(1,h,t) = "move a disk from rod h to rod t" (there is only ane disk left).

The number of moves required by this solution is 2 n  − 1. If the objective is to maximize the number of moves (without cycling) then the dynamic programming functional equation is slightly more complicated and three n  − 1 moves are required.[12]

Egg dropping puzzle [edit]

The post-obit is a description of the instance of this famous puzzle involving Northward=ii eggs and a edifice with H=36 floors:[13]

Suppose that we wish to know which stories in a 36-story edifice are condom to driblet eggs from, and which will crusade the eggs to break on landing (using U.South. English language terminology, in which the first floor is at ground level). We make a few assumptions:
  • An egg that survives a autumn can exist used once more.
  • A broken egg must be discarded.
  • The consequence of a autumn is the same for all eggs.
  • If an egg breaks when dropped, so it would interruption if dropped from a college window.
  • If an egg survives a fall, and then it would survive a shorter fall.
  • It is non ruled out that the commencement-floor windows break eggs, nor is it ruled out that eggs tin survive the 36th-flooring windows.
If only i egg is available and we wish to be sure of obtaining the right result, the experiment tin can be carried out in just one fashion. Drib the egg from the first-floor window; if information technology survives, driblet it from the second-floor window. Continue upward until it breaks. In the worst example, this method may crave 36 droppings. Suppose 2 eggs are available. What is the lowest number of egg-droppings that is guaranteed to piece of work in all cases?

To derive a dynamic programming functional equation for this puzzle, let the state of the dynamic programming model exist a pair s = (n,1000), where

n = number of examination eggs bachelor, northward = 0, ane, 2, 3, ..., N − 1.
thou = number of (sequent) floors yet to be tested, yard = 0, one, 2, ..., H − 1.

For case, southward = (2,6) indicates that two test eggs are available and half dozen (sequent) floors are nevertheless to be tested. The initial land of the process is due south = (Due north,H) where N denotes the number of examination eggs available at the commencement of the experiment. The process terminates either when at that place are no more exam eggs (n = 0) or when grand = 0, whichever occurs first. If termination occurs at state s = (0,1000) and 1000 > 0, and so the test failed.

Now, let

W(due north,1000) = minimum number of trials required to identify the value of the disquisitional floor under the worst-case scenario given that the procedure is in state s = (due north,k).

Then it can be shown that[xiv]

Westward(northward,k) = ane + min{max(W(northward − 1, x − 1), West(n,one thousandx)): x = i, two, ..., g }

with W(northward,0) = 0 for all northward > 0 and Westward(1,grand) = k for allgrand. It is like shooting fish in a barrel to solve this equation iteratively past systematically increasing the values of n andm.

Faster DP solution using a different parametrization [edit]

Discover that the above solution takes O ( n thou 2 ) {\displaystyle O(nk^{2})} fourth dimension with a DP solution. This tin can be improved to O ( n k log thou ) {\displaystyle O(nk\log grand)} fourth dimension by binary searching on the optimal x {\displaystyle x} in the above recurrence, since W ( north 1 , ten 1 ) {\displaystyle Westward(n-1,x-1)} is increasing in 10 {\displaystyle 10} while Due west ( n , k x ) {\displaystyle Westward(northward,k-ten)} is decreasing in x {\displaystyle 10} , thus a local minimum of max ( Due west ( due north i , x one ) , W ( n , k 10 ) ) {\displaystyle \max(West(n-1,x-1),W(due north,k-ten))} is a global minimum. Also, by storing the optimal x {\displaystyle 10} for each cell in the DP table and referring to its value for the previous prison cell, the optimal x {\displaystyle x} for each cell can be found in constant time, improving information technology to O ( n thousand ) {\displaystyle O(nk)} time. Nonetheless, at that place is an even faster solution that involves a different parametrization of the problem:

Allow k {\displaystyle grand} be the total number of floors such that the eggs break when dropped from the k {\displaystyle thou} thursday floor (The example above is equivalent to taking k = 37 {\displaystyle 1000=37} ).

Permit one thousand {\displaystyle m} be the minimum floor from which the egg must be dropped to be broken.

Permit f ( t , n ) {\displaystyle f(t,n)} be the maximum number of values of chiliad {\displaystyle thousand} that are distinguishable using t {\displaystyle t} tries and n {\displaystyle n} eggs.

Then f ( t , 0 ) = f ( 0 , n ) = 1 {\displaystyle f(t,0)=f(0,north)=1} for all t , n 0 {\displaystyle t,due north\geq 0} .

Let a {\displaystyle a} be the floor from which the first egg is dropped in the optimal strategy.

If the beginning egg bankrupt, one thousand {\displaystyle one thousand} is from 1 {\displaystyle one} to a {\displaystyle a} and distinguishable using at most t 1 {\displaystyle t-1} tries and north one {\displaystyle n-i} eggs.

If the first egg did not pause, m {\displaystyle 1000} is from a + one {\displaystyle a+one} to yard {\displaystyle k} and distinguishable using t 1 {\displaystyle t-i} tries and n {\displaystyle northward} eggs.

Therefore, f ( t , north ) = f ( t 1 , due north 1 ) + f ( t i , north ) {\displaystyle f(t,n)=f(t-1,due north-ane)+f(t-1,north)} .

Then the problem is equivalent to finding the minimum 10 {\displaystyle x} such that f ( x , n ) k {\displaystyle f(x,n)\geq thousand} .

To do so, we could compute { f ( t , i ) : 0 i due north } {\displaystyle \{f(t,i):0\leq i\leq n\}} in order of increasing t {\displaystyle t} , which would take O ( n x ) {\displaystyle O(nx)} time.

Thus, if nosotros separately handle the instance of n = one {\displaystyle n=ane} , the algorithm would take O ( due north k ) {\displaystyle O(n{\sqrt {k}})} time.

But the recurrence relation can in fact be solved, giving f ( t , n ) = i = 0 northward ( t i ) {\displaystyle f(t,n)=\sum _{i=0}^{n}{\binom {t}{i}}} , which can be computed in O ( north ) {\displaystyle O(n)} time using the identity ( t i + 1 ) = ( t i ) t i i + 1 {\displaystyle {\binom {t}{i+one}}={\binom {t}{i}}{\frac {t-i}{i+one}}} for all i 0 {\displaystyle i\geq 0} .

Since f ( t , n ) f ( t + 1 , due north ) {\displaystyle f(t,north)\leq f(t+1,n)} for all t 0 {\displaystyle t\geq 0} , we tin can binary search on t {\displaystyle t} to find x {\displaystyle ten} , giving an O ( north log g ) {\displaystyle O(due north\log k)} algorithm.[fifteen]

Matrix chain multiplication [edit]

Matrix chain multiplication is a well-known example that demonstrates utility of dynamic programming. For instance, engineering applications often take to multiply a concatenation of matrices. It is non surprising to detect matrices of big dimensions, for example 100×100. Therefore, our task is to multiply matrices A 1 , A 2 , . . . . A n {\displaystyle A_{1},A_{2},....A_{n}} . Matrix multiplication is not commutative, but is associative; and nosotros tin can multiply simply two matrices at a time. And so, we can multiply this chain of matrices in many different ways, for case:

((Aane × A2) × A3) × ... Anorth
A1×(((A2×A3)× ... ) × An)
(A1 × A2) × (Athree × ... Anorthward)

and then on. There are numerous ways to multiply this chain of matrices. They will all produce the same final result, notwithstanding they will accept more or less time to compute, based on which particular matrices are multiplied. If matrix A has dimensions m×north and matrix B has dimensions n×q, then matrix C=A×B will have dimensions thou×q, and will require 1000*n*q scalar multiplications (using a simplistic matrix multiplication algorithm for purposes of illustration).

For example, let u.s. 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 volition exist of size m×southward and can be calculated in 2 means shown below:

  1. Ax(B×C) This order of matrix multiplication volition require nps + mns scalar multiplications.
  2. (A×B)×C This social club of matrix multiplication volition crave mnp + mps scalar calculations.

Let united states of america assume that thousand = 10, n = 100, p = 10 and s = k. So, the first way to multiply the concatenation will require i,000,000 + 1,000,000 calculations. The 2nd way will require only 10,000+100,000 calculations. Obviously, the 2nd way is faster, and we should multiply the matrices using that organization of parenthesis.

Therefore, our decision is that the order of parenthesis matters, and that our task is to find the optimal club of parenthesis.

At this point, nosotros take several choices, one of which is to design a dynamic programming algorithm that will separate the problem into overlapping problems and calculate the optimal arrangement of parenthesis. The dynamic programming solution is presented below.

Let'due south call m[i,j] the minimum number of scalar multiplications needed to multiply a chain of matrices from matrix i to matrix j (i.due east. Ai × .... × Aj, i.e. i<=j). Nosotros split the chain at some matrix k, such that i <= k < j, and attempt to observe out which combination produces minimum m[i,j].

The formula is:

          if          i = j, m[i,j]= 0          if          i < j, one thousand[i,j]= min over all possible values of k          (thou[i,k]+thou[grand+ane,j] +                                                                                                                                                        p                                                      i                                                                                    one                                                                                                                                                    p                                                      one thousand                                                                                                                                                    p                                                      j                                                                                                                {\displaystyle p_{i-one}*p_{thousand}*p_{j}}                                                                          )        

where grand ranges from i to j − 1.

This formula can be coded as shown below, where input parameter "chain" is the chain of matrices, i.e. A i , A 2 , . . . A n {\displaystyle A_{1},A_{2},...A_{n}} :

          part          OptimalMatrixChainParenthesis(concatenation)     n = length(chain)          for          i = 1, n         grand[i,i] = 0          // Since it takes no calculations to multiply one matrix          for          len = 2, n          for          i = 1, n - len + i             j = i + len -1             grand[i,j] = infinity          // So that the first calculation updates          for          k = i, j-1          q = grand[i, thou] + m[k+i, j] +                                                                                                                                                        p                                                      i                                                                                    1                                                                                                                                                    p                                                      k                                                                                                                                                    p                                                      j                                                                                                                {\displaystyle p_{i-1}*p_{k}*p_{j}}                                                                                              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 identify the parenthesis        

So far, we have calculated values for all possible g[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" s[i, j]. For instance, if we are multiplying chain A1×A2×A3×A4 , and it turns out that chiliad[1, 3] = 100 and s[1, 3] = ii, that means that the optimal placement of parenthesis for matrices 1 to three is ( A one × A 2 ) × A three {\displaystyle (A_{ane}\times A_{2})\times A_{3}} and to multiply those matrices volition crave 100 scalar adding.

This algorithm will produce "tables" thousand[, ] and s[, ] that will have entries for all possible values of i and j. The terminal solution for the entire concatenation is m[1, n], with corresponding split up at s[1, due north]. Unraveling the solution volition exist recursive, starting from the summit and continuing until we achieve the base case, i.due east. multiplication of single matrices.

Therefore, the next step is to really split the chain, i.eastward. to place the parenthesis where they (optimally) vest. For this purpose we could use the post-obit algorithm:

          function          PrintOptimalParenthesis(south, i, j)          if          i = j         impress "A"i          else          print "("          PrintOptimalParenthesis(s, i, s[i, j])          PrintOptimalParenthesis(s, s[i, j] + ane, j)          print ")"        

Of course, this algorithm is non useful for actual multiplication. This algorithm is just a user-friendly way to see what the event looks similar.

To really multiply the matrices using the proper splits, we need the following algorithm:

                        function            MatrixChainMultiply            (            chain            from            1            to            northward            )            // returns the final matrix, i.e. A1×A2×... ×An            OptimalMatrixChainParenthesis            (            chain            from            1            to            n            )            // this will produce s[ . ] and m[ . ] "tables"            OptimalMatrixMultiplication            (            s            ,            concatenation            from            one            to            n            )            // actually multiply            function            OptimalMatrixMultiplication            (            south            ,            i            ,            j            )            // returns the effect of multiplying a chain of matrices from Ai to Aj in optimal manner            if            i            <            j            // keep on splitting the chain and multiplying the matrices in left and right sides            LeftSide            =            OptimalMatrixMultiplication            (            s            ,            i            ,            s            [            i            ,            j            ])            RightSide            =            OptimalMatrixMultiplication            (            s            ,            southward            [            i            ,            j            ]            +            1            ,            j            )            render            MatrixMultiply            (            LeftSide            ,            RightSide            )            else            if            i            =            j            return            Ai            // matrix at position i            else            print            "fault, i <= j must hold"            function            MatrixMultiply            (            A            ,            B            )            // office that multiplies two matrices            if            columns            (            A            )            =            rows            (            B            )            for            i            =            1            ,            rows            (            A            )            for            j            =            1            ,            columns            (            B            )            C            [            i            ,            j            ]            =            0            for            k            =            1            ,            columns            (            A            )            C            [            i            ,            j            ]            =            C            [            i            ,            j            ]            +            A            [            i            ,            k            ]            *            B            [            k            ,            j            ]            return            C            else            impress            "error, incompatible dimensions."          

History [edit]

The term dynamic programming was originally used in the 1940s by Richard Bellman to describe the procedure of solving problems where one needs to find the best decisions one after some other. By 1953, he refined this to the mod meaning, referring specifically to nesting smaller decision problems within larger decisions,[xvi] and the field was thereafter recognized by the IEEE equally a systems analysis and engineering topic. Bellman's contribution is remembered in the name of the Bellman equation, a primal consequence of dynamic programming which restates an optimization problem in recursive form.

Bellman explains the reasoning backside the term dynamic programming in his autobiography, Center of the Hurricane: An Autobiography:

I spent the Fall quarter (of 1950) at RAND. My first task was to discover a proper noun for multistage determination processes. An interesting question is, "Where did the proper name, dynamic programming, come up from?" The 1950s were not skilful years for mathematical research. Nosotros had a very interesting gentleman in Washington named Wilson. He was Secretary of Defense, and he actually had a pathological fear and hatred of the word "research". I'chiliad not using the term lightly; I'yard using it precisely. His face would suffuse, he would turn crimson, and he would get violent if people used the term research in his presence. You tin imagine how he felt, so, about the term mathematical. The RAND Corporation was employed by the Air Strength, and the Air Strength had Wilson every bit its dominate, essentially. Hence, I felt I had to practice 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 identify I was interested in planning, in decision making, in thinking. Merely planning, is not a good word for various reasons. I decided therefore to use the word "programming". I wanted to become across the idea that this was dynamic, this was multistage, this was time-varying. I thought, allow's kill two birds with one rock. Allow's take a give-and-take that has an admittedly precise meaning, namely dynamic, in the classical physical sense. It also has a very interesting belongings as an adjective, and that is it's impossible to use the word dynamic in a debasing sense. Try thinking of some combination that volition perhaps give information technology a pejorative meaning. It'due south impossible. Thus, I thought dynamic programming was a good proper noun. It was something non even a Congressman could object to. So I used it equally an umbrella for my activities.

Richard Bellman, Heart of the Hurricane: An Autobiography (1984, page 159)

The word dynamic was chosen by Bellman to capture the fourth dimension-varying aspect of the problems, and because information technology sounded impressive.[11] The word programming referred to the use of the method to find an optimal program, in the sense of a armed services 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.[17]

The higher up explanation of the origin of the term is lacking. Equally Russell and Norvig in their book have written, referring to the above story: "This cannot be strictly true, because his first newspaper using the term (Bellman, 1952) appeared before Wilson became Secretarial assistant of Defense in 1953."[18] Also, there is a comment in a speech by Harold J. Kushner, where he remembers Bellman. Quoting Kushner equally he speaks of Bellman: "On the other hand, when I asked him the same question, he replied that he was trying to upstage Dantzig'due south linear programming past adding dynamic. Perhaps both motivations were true."

Algorithms that use dynamic programming [edit]

  • Recurrent solutions to lattice models for poly peptide-Deoxyribonucleic acid binding
  • Backward induction as a solution method for finite-horizon detached-time dynamic optimization problems
  • Method of undetermined coefficients can exist used to solve the Bellman equation in infinite-horizon, detached-fourth dimension, discounted, time-invariant dynamic optimization problems
  • Many string algorithms including longest common subsequence, longest increasing subsequence, longest common substring, Levenshtein distance (edit distance)
  • Many algorithmic problems on graphs tin be solved efficiently for graphs of bounded treewidth or bounded clique-width by using dynamic programming on a tree decomposition of the graph.
  • The Cocke–Younger–Kasami (CYK) algorithm which determines whether and how a given string tin can exist generated by a given context-costless grammar
  • Knuth's word wrapping algorithm that minimizes raggedness when discussion wrapping text
  • The apply of transposition tables and refutation tables in computer chess
  • The Viterbi algorithm (used for hidden Markov models, and particularly in part of voice communication tagging)
  • The Earley algorithm (a type of nautical chart parser)
  • The Needleman–Wunsch algorithm and other algorithms used in bioinformatics, including sequence alignment, structural alignment, RNA structure prediction[eleven]
  • Floyd'southward all-pairs shortest path algorithm
  • Optimizing the order for chain matrix multiplication
  • Pseudo-polynomial time algorithms for the subset sum, knapsack and partition issues
  • The dynamic time warping algorithm for calculating the global distance betwixt 2 time serial
  • The Selinger (a.k.a. System R) algorithm for relational database query optimization
  • De Boor algorithm for evaluating B-spline curves
  • Duckworth–Lewis method for resolving the trouble when games of cricket are interrupted
  • The value iteration method for solving Markov decision processes
  • Some graphic image edge post-obit pick methods such every bit the "magnet" choice tool in Photoshop
  • Some methods for solving interval scheduling issues
  • Some methods for solving the travelling salesman trouble, either exactly (in exponential time) or approximately (eastward.one thousand. via the bitonic tour)
  • Recursive to the lowest degree squares method
  • Trounce tracking in music information retrieval
  • Adaptive-critic preparation strategy for artificial neural networks
  • Stereo algorithms for solving the correspondence problem used in stereo vision
  • Seam etching (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'south algorithm for the maximum subarray trouble
  • Optimization of electric generation expansion plans in the Wein Automatic Organization Planning (WASP) package

Run into also [edit]

  • Convexity in economics
  • Greedy algorithm
  • Non-convexity (economics)
  • Stochastic programming
  • Stochastic dynamic programming
  • Reinforcement learning

References [edit]

  1. ^ a b 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.
  2. ^ Kamien, M. I.; Schwartz, N. L. (1991). Dynamic Optimization: The Calculus of Variations and Optimal Command in Economic science and Management (2d ed.). New York: Elsevier. p. 261. ISBN978-0-444-01609-six.
  3. ^ Kirk, Donald E. (1970). Optimal Control Theory: An Introduction. Englewood Cliffs, NJ: Prentice-Hall. pp. 94–95. ISBN978-0-thirteen-638098-six.
  4. ^ "One thousand. Memo". J Vocabulary. J Software. Retrieved 28 October 2011.
  5. ^ DeLisi, Biopolymers, 1974, Volume thirteen, Consequence 7, pages 1511–1512, July 1974
  6. ^ Gurskiĭ GV, Zasedatelev AS, Biofizika, 1978 Sep-October;23(5):932-46
  7. ^ Sniedovich, Yard. (2006), "Dijkstra's algorithm revisited: the dynamic programming connexion" (PDF), Journal of Control and Cybernetics, 35 (3): 599–620. Online version of the paper with interactive computational modules.
  8. ^ Denardo, Eastward.Five. (2003), Dynamic Programming: Models and Applications, Mineola, NY: Dover Publications, ISBN978-0-486-42810-9
  9. ^ Sniedovich, One thousand. (2010), Dynamic Programming: Foundations and Principles, Taylor & Francis, ISBN978-0-8247-4099-3
  10. ^ Dijkstra 1959, p. 270 harvnb error: no target: CITEREFDijkstra1959 (help)
  11. ^ a b c Eddy, S. R. (2004). "What is Dynamic Programming?". Nature Biotechnology. 22 (7): 909–910. doi:10.1038/nbt0704-909. PMID 15229554. S2CID 5352062.
  12. ^ Moshe Sniedovich (2002), "OR/MS Games: 2. The Towers of Hanoi Problem", INFORMS Transactions on Educational activity, 3 (1): 34–51, doi:10.1287/ited.3.1.45.
  13. ^ Konhauser J.D.Eastward., Velleman, D., and Wagon, S. (1996). Which way did the Cycle Get? Dolciani Mathematical Expositions – No eighteen. The Mathematical Association of America.
  14. ^ Sniedovich, Moshe (2003). "OR/MS Games: 4. The Joy of Egg-Dropping in Braunschweig and Hong Kong". INFORMS Transactions on Education. 4: 48–64. doi:ten.1287/ited.four.1.48.
  15. ^ Dean Connable Wills, Connections between combinatorics of permutations and algorithms and geometry
  16. ^ Stuart Dreyfus. "Richard Bellman on the birth of Dynamical Programming".
  17. ^ Nocedal, J.; Wright, S. J. (2006). Numerical Optimization . Springer. p. 9. ISBN9780387303031.
  18. ^ Russell, Southward.; Norvig, P. (2009). Artificial Intelligence: A Modern Approach (third ed.). Prentice Hall. ISBN978-0-thirteen-207148-2.

Further reading [edit]

  • Adda, Jerome; Cooper, Russell (2003), Dynamic Economics, MIT Printing, ISBN9780262012010 . An accessible introduction to dynamic programming in economics. MATLAB lawmaking for the book.
  • Bellman, Richard (1954), "The theory of dynamic programming", Bulletin of the American Mathematical Society, 60 (6): 503–516, doi:10.1090/S0002-9904-1954-09848-8, MR 0067459 . Includes an extensive bibliography of the literature in the area, up to the yr 1954.
  • Bellman, Richard (1957), Dynamic Programming, Princeton University Press . Dover paperback edition (2003), ISBN 0-486-42809-5.
  • Cormen, Thomas H.; Leiserson, Charles East.; Rivest, Ronald L.; Stein, Clifford (2001), Introduction to Algorithms (second ed.), MIT Press & McGraw–Colina, ISBN978-0-262-03293-3 . Especially pp. 323–69.
  • Dreyfus, Stuart E.; Constabulary, Averill M. (1977), The Fine art and Theory of Dynamic Programming, Bookish Printing, ISBN978-0-12-221860-6 .
  • Giegerich, R.; Meyer, C.; Steffen, P. (2004), "A Discipline of Dynamic Programming over Sequence Data" (PDF), Science of Computer Programming, 51 (3): 215–263, doi:10.1016/j.scico.2003.12.005 .
  • Meyn, Sean (2007), Control Techniques for Complex Networks, Cambridge Academy Press, ISBN978-0-521-88441-9, archived from the original on 2010-06-19 .
  • Sritharan, S. S. (1991). "Dynamic Programming of the Navier-Stokes Equations". Systems and Command Messages. 16 (4): 299–307. doi:x.1016/0167-6911(91)90020-f.
  • Stokey, Nancy; Lucas, Robert Due east.; Prescott, Edward (1989), Recursive Methods in Economical Dynamics, Harvard Univ. Press, ISBN978-0-674-75096-8 .

External links [edit]

  • A Tutorial on Dynamic programming
  • MIT grade on algorithms – Includes a video lecture on DP along with lecture notes, see lecture 15.
  • Applied Mathematical Programming by Bradley, Hax, and Magnanti, Affiliate 11
  • More DP Notes
  • King, Ian, 2002 (1987), "A Elementary Introduction to Dynamic Programming in Macroeconomic Models." An introduction to dynamic programming every bit an important tool in economic theory.
  • Dynamic Programming: from novice to advanced A TopCoder.com article by Dumitru on Dynamic Programming
  • Algebraic Dynamic Programming – a formalized framework for dynamic programming, including an entry-level course to DP, University of Bielefeld
  • Dreyfus, Stuart, "Richard Bellman on the birth of Dynamic Programming."
  • Dynamic programming tutorial
  • A Gentle Introduction to Dynamic Programming and the Viterbi Algorithm
  • Tabled Prolog BProlog, XSB, SWI-Prolog
  • IFORS online interactive dynamic programming modules including, shortest path, traveling salesman, knapsack, false money, egg dropping, bridge and torch, replacement, chained matrix products, and critical path problem.

georgewhingle.blogspot.com

Source: https://en.wikipedia.org/wiki/Dynamic_programming

0 Response to "On t Talk to Me or My Subproblem Every Again"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel