Dynamic Programming |
Greedy Method |
1. Dynamic Programming is used to obtain the optimal solution. |
1. Greedy Method is also used to get the optimal solution. |
2. In Dynamic Programming, we choose at each step, but the choice may depend on the solution to sub-problems. |
2. In a greedy Algorithm, we make whatever choice seems best at the moment and then solve the sub-problems arising after the choice is made. |
3. Less efficient as compared to a greedy approach |
3. More efficient as compared to a greedy approach |
4. Example: 0/1 Knapsack |
4. Example: Fractional Knapsack |
5. It is guaranteed that Dynamic Programming will generate an optimal solution using Principle of Optimality. |
5. In Greedy Method, there is no such guarantee of getting Optimal Solution. |