DEV Community


Posted on

Dynamic Programming Vs Greedy

Dynamic Programming:

It just solves problems by combining the sub problems to solutions only of the sub problems were independent.
It can be used for solving both mathematical optimization method and computer programming method.
For example, it can be used for finding the shortest path in graph.
• Many decision sequence may be generated.
• Highly reliable
• Bottom-up approach
• There is no special set of feasible solution
• Less Efficiency
• Overlapping subproblems choose feasible solution

Alt Text

The algorithm used is:

Alt Text

Greedy Method:

Greedy method solves problems step by step which leads to global optimization solution.
• Generates a single decision sequence
• Less reliable
• Top to bottom approach
• Contain a special set of feasible set of solutions.
• More efficiency
• Overlapping subproblems cannot be handled.

Alt Text
Algorithm for greedy is:
//In Greedy approach D is domain
//from which solution is to be obtained of size n
//Initially assume
for i<-1 to n do{
if(Feasible solution,s))then
return solution

Top comments (0)