# Where we Use Dynamic Programming and Greedy Algorithm? [closed]

Can someone tell me where we use Dynamic/Greedy algorithm and how we trace from the question that it will solved by any one of the above?

Thanks

• Your question is missing some details. Also, it is somewhat broad. I recommend solving several exercises to get a feel for where dynamic programming is useful, and where greedy algorithms are effective. Dec 18, 2016 at 11:09
• My Question is really simple and clear and I have got the answer thanks though . Dec 23, 2016 at 19:57

Greedy Algorithm:

An algorithm that always takes the best immediate, or local, solution while finding an answer. Greedy algorithms find the overall, or globally, optimal solution for some optimization problems, but may find less-than-optimal solutions for some instances of other problems. .

Problems that can be solved by a Greedy Algorithm will have two properties:

1. Greedy Choice Property;
2. Optimal Substructure.

Essentially, Greedy Algorithms solve combinatorial problems having the properties of matroid.

For more detail you can consult Introduction to Algorithm.

Dynamic Programming:

Solve an optimization problem by caching subproblem solutions (memoization) rather than recomputing them. 

Dynamic Programming algorithms are often used for optimization because it will examine the previously solved subproblems and will combine their solutions to give the best solution for the given problem.

Now, problems that can be solved by a Dynamic Programming Algorithm will have this necessary condition:

Principle of Optimality: An optimal policy has the property that whatever the initial state and initial decision are, the remaining decisions must constitute an optimal policy with regard to the state resulting from the first decision. 

• This really helped me :) Dec 23, 2016 at 19:55