Differentiate between Dynamic Programming and Greedy Method


Differentiate between Dynamic Programming and Greedy Method

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.

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.