While the former reduces a possibly exponential time complexity to a polynomial one, the latter tries to improve upon the running time of an algorithm that is already of polynomial time complexity. As can be seen via examples, there is marked difference in the problems that subject themselves to dynamic programming algorithms, and those coming under divide-and-conquer algorithms.
both of them solve smaller sub-problems in order to find the solution to the given problem. Now, how can it test all such solutions in polynomial time? The answer is that it builds upon the solution stage-by-stage, and for computing values at each stage, it uses the pre-computed values of the previous stages.ĭoes the divide-and-conquer paradigm also not do the same, i.e. For an optimization problem, it searches through the space of possible solutions, which may be exponential in size. Dynamic Programming is a very convenient methodology to compute in polynomial time a solution that seemingly requires exponential time.