## Dynamic Programming vs Divide and ConquerBefore knowing about the differences between dynamic programming and divide and conquer, we should know about dynamic programming and divide and conquer separately. ## What is Divide and Conquer?Divide and conquer is a strategy used for solving a problem. A strategy can be defined as an approach for solving a problem. To solve a computational problem, this strategy has been designed. There are various techniques available to solve the problem, but we have to decide whether the technique is suitable for the problem or not. Suppose the problem is large, then we break the problem into smaller sub-problems and then solve these subproblems individually. Once all the sub-problems are solved, we will combine the solutions of all the sub-problems to find the solution to the big problem. If the sub-problem is also large, then apply the divide and conquer strategy again to solve the sub-problem. The constraint of divide and conquer strategy is that the sub-problem should be the same as the major problem. Suppose the major problem is sort then the sub-problems should also be sort. The divide and conquer strategy is recursive in nature. If the problem is big, then we solve that problem recursively.
Since the dynamic programming is recursive so procedures are recursive and algorithms are recursive.
- Merge sort: Divide the array into two halves, recursively sort the left and right halves, then we will merge these two halves. This technique is known as a merge sort.
- Quick sort: First, partition the array into small items and large items, then recursively sort these two sets. This technique is known as a Quick sort.
- Searching: Divide and conquer strategy is used in
*binary search.* - Sorting: Merge sort and Quick sort are the example of the Divide and conquer technique.
- Tree traversals
- Matrix multiplication
## What is Dynamic Programming?Dynamic programming means dividing the optimization problem into simpler sub-problems and storing the solution to each sub-problem so that each sub-problem can be solved once. Once all the sub-problems are solved, we will concatenate the results of each sub-problem to find the solution to the initial problem.
- Dynamic performing is performed in such a way that the problem can be broken down into optimal sub-problems.
- It defines the value of the solution recursively by showing it in terms of optimal solutions for smaller sub-problems.
- We will calculate the value of optimal solutions.
- Construct the optimal solution from the computed values.
- Optimal substructure: An optimal solution to the problem contains the optimal solutions to all subproblems.
- Overlapping subproblem: A recursive solution contains a small number of distinct subproblems repeated many times.
## Techniques of Dynamic programming
**Bottom-up approach:**Suppose I want to be an amazing coder. First, I will do practising then I will take part in contests. I will practice more and try to improve. After working hard, I will be an amazing coder. This is a bottom-up approach.**Top-down approach:**This approach is the opposite of the bottom-up approach. I will start with the final solution. First, I will be an amazing coder. Then, I will practice more and try to improve. I will take part in contests, and then I will do the practice.
## Differences between the Divide and Conquer and Dynamic Programming
Next TopicMaximum Sum Increasing Subsequence |