How to know when to use Dynamic Programming?

663 Views Asked by At

Given any problem, how do I know whether it is solvable using Dynamic Programming? For example: consider the rod cutting problem. Now, how do I know whether dynamic programming will give me an optimal answer? Basically my question is: how do I check if a problem follows the "Principle of Optimality" - that optimal solution of every problem involves the optimal solution of a sub problem. And are there any problems that don't follow this principle? (If there aren't, my original question becomes redundant, of course!)

1

There are 1 best solutions below

0
On

A nice example of problem which does not follow the principle of optimality is the "longest simple path". This is: given a graph $G$ and two vertices $v$ and $w$, which is the longest simple path from $v$ to $w$ (in terms of the number of edges)?

A easy example to see that this fails is when your graph is a cycle.