I have been trying to understand Dynamic Programming, and what I understood is that there are two parts of DP.
I understand the second one, but I am not able to understand the first one.
Optimal substructure means, that any optimal solution to a problem of size n , is based on an optimal solution to the same problem when considering n' < n elements. That means, when building your solution for a problem of size n , you split the problem to smaller problems, one of them of size n' .
Principle of Optimality. Definition: A problem is said to satisfy the Principle of Optimality if the subsolutions of an optimal solution of the problem are themesleves optimal solutions for their subproblems. Examples: The shortest path problem satisfies the Principle of Optimality.
A problem has an optimal substructure property if an optimal solution of the given problem can be obtained by using the optimal solution of its subproblems. Dynamic Programming takes advantage of this property to find a solution.
Optimal substructure means, that any optimal solution to a problem of size n
, is based on an optimal solution to the same problem when considering n' < n
elements.
That means, when building your solution for a problem of size n
, you split the problem to smaller problems, one of them of size n'
. Now, you need only to consider the optimal solution to n'
, and not all possible solutions to it, based on the optimal substructure property.
An example is the knapsack problem:
D(i,k) = min { D(i-1,k), D(i-1,k-weight(i)) + cost(i) }
The optimal substructure assumption here, is D(i,k)
can check only optimal solutions to D(i-1,k)
, and none optimal solutions are not considered.
An example where this does not hold is the Vertex Cover problem.
If you have a graph G=(V,E), assume you have an optimal solution to a subgraph G'=(V',E[intersection]V'xV')
such that V' <= V
- the optimal solution for G
does not have to be consisted of of the optimal solution for G'
/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With