AfterAcademy Tech
•
29 Feb 2020

Both Dynamic Programming and Greedy are algorithmic paradigms used to solve optimization problems.
Greedy Approach deals with forming the solution step by step by choosing the local optimum at each step and finally reaching a global optimum. Therefore, Greedy Approach does not deal with multiple possible solutions, it just builds the one solution that it believes to be correct. In other words, the principle of Greedy is that we assume that choosing the local optimum at each stage will lead to form the global optimum.
Dynamic Programming(DP) does not deal with such kinds of uncertain assumptions. DP finds a solution to all subproblems and chooses the best ones to form the global optimum.
To read about each algorithmic paradigm, read these two blogs: What are Greedy Algorithms? and Idea of Dynamic Programming.
Dynamic Programming is guaranteed to reach the correct answer each and every time whereas Greedy is not.
This is because, in Dynamic Programming, we form the global optimum by choosing at each step depending on the solution of previous smaller subproblems whereas, in Greedy Approach, we consider the choice that seems the best at the moment.
We don’t use Dynamic Programming with all problems because Greedy is faster when it delivers the correct solution since it only deals with one subproblem. Also, Dynamic Programming works only when there are overlapping subproblems.
Whenever an optimization problem has an optimal substructure property, we know that it might be solved with Greedy and DP. But how to choose between these two?
Well, if the problem holds the Greedy Choice Property, its best to solve it using the Greedy Approach.
And if it has overlapping subproblems, solve it with Dynamic Programming.
There are some problems that can be solved using both Greedy and DP like Coin Change Problems(can be solved using greedy for a certain type of input). In such cases, it is best to solve it using Greedy because it will be faster since it only solves one subproblem and DP solves multiple subproblems before reaching the final answer.
If an optimization problem has an optimal substructure, it may be solved using Greedy or Dynamic Programming. Now you need to look further for some other properties →
AfterAcademy Tech
Divide and Conquer and Dynamic Programming are two most used problem-solving skills in Data Structures. In this blog, we will see the similarities and difference between Dynamic Programming and Divide-and-Conquer approaches.

AfterAcademy Tech
This blog deals with the introduction of greedy algorithms for beginners and enthusiasts.

AfterAcademy Tech
Dynamic Programming is one of the most commonly used approach of problem-solving during coding interviews. We will discuss how can we approach to a problem using Dynamic Programming and also discuss the concept of Time-Memory Trade-Off.

AfterAcademy Tech
In this blog, we will learn the difference between Multiprogramming, Multiprocessing, and Multitasking. These terms come into play when we talk about our processes and the processors. Let's see the difference between these.
