Juan Camilo Alfonso 70990 Programacion Dinamica
Juan Camilo Alfonso 70990 Programacion Dinamica
Dynamic Programming
Código: 70990
7 de noviembre de 2021
2
The following essential characteristics are what you must have a problem with before
dynamic programming can be applied: Optimal substructure This characteristic
expresses that an optimization problem can be solved by combining the optimal
solutions of the secondary problems that comprise it. These optimal substructures are
described by recursion. For example, in a graph an optimal substructure will be
presented in the shortest path r that goes from a vertex s to a vertex t: That is, in this
shortest path r any intermediate vertex i can be taken. If r is really the shortest route,
then it can be divided into the sub-routes r1 (from s to i) and r2 (from i to t), in such a
way that these are in turn the shortest routes between the corresponding vertices.
Therefore, to find the shortest routes, the solution can be easily formulated recursively,
which is what the Floyd-Warshall algorithm does. Overlapping subproblems The
subproblem space should be small. That is, any recursive algorithm that solves a
problem will have to solve the same subproblems over and over again, instead of
generating new subproblems. For example, to generate the Fibonacci series, this
recursive formulation can be considered: Fn = F (n – 1) + F (n – 2), taking as a base
case that F1 = F2 = 1. Then we will have: F33 = F32 + F31, and F32 = F31 + F30. As
you can see, F31 is being resolved into the recursive subtrees of both F33 and F32.
3
Although the total number of subproblems is really small, if you adopt a recursive
solution like this you will end up solving the same problems over and over again. This is
taken into account by dynamic programming, so it solves each subproblem only once.
This can be accomplished in two ways: Top-down approach If the solution to any
problem can be recursively formulated using the solution of its subproblems, and if
these subproblems overlap, then the solutions to the subproblems can easily be
memorized or stored in a table. Each time a new subproblem solution is sought, the
table will be checked to see if it was previously solved. In case a solution is stored, it will
be used instead of calculating it again. Otherwise, the subproblem will be solved, storing
the solution in the table. Bottom-up approach After the solution of a problem is
recursively formulated in terms of its subproblems, an attempt can be made to
reformulate the problem in an ascending manner: first, an attempt will be made to solve
the subproblems and use their solutions to arrive at solutions to the larger subproblems.
This is also generally done in table form, iteratively generating solutions to larger and
larger subproblems by using solutions to smaller subproblems. For example, if the
values of F31 and F30 are already known, the value of F32 can be calculated directly.
Comparison with other techniques One significant feature of a problem that can be
solved dynamically is that it should have subproblems overlapping. This is what
distinguishes dynamic programming from the divide and conquer technique, where it is
not necessary to store the simplest values. It is similar to recursion, since when
calculating the base cases the final value can be determined inductively. This bottom-up
approach works well when a new value depends only on previously calculated values.
4
Bibliografía
dinamica.html