Divide and Conquer - Introduction
What is Divide and Conquer?
Divide and Conquer is an algorithm paradigm in which we break down a given problem into smaller sub-problems of similar type until the sub-problems are small enough to be solved directly. The solution to these sub-problems are then combined to give a solution to the original problem.
Study the diagram below, it will then make more sense about what we do in Divide and Conquer :
Where to Apply Divide and Conquer?
The Divide and Conquer can be applied to all those problems that show Optimal Substructure property.
So, What is this Optimal Substructure property now?
If we can break down a problem into similar sub-problems and the solution of these sub-problems can be used to create the solution of the whole problem, then that problem is said to have the Optimal Substructure property.
For eg. : Fibonacci(n) = Fibonacci(n-1) + Fibonacci(n-2), In this example, we can see that if we want to find the Fibonacci number at the nth place, we can break this problem into smaller sub-problems of finding Fibonacci number at (n-1) and (n-2) places and then adding the solution of these smaller sub-problems to get the solution of whole problem that if finding Fibonacci(n)
Famous Problems (relevant to coding interview) that can be solved using Divide and Conquer
Important Note: I would highly recommend solving these problems. They are common and are mostly asked problems, which will also help to gain an understanding of Divide and Conquer. As Divide and Conquer is an algorithmic paradigm, there is not much theory to it. To really understand Divide and Conquer, we should emphasize more on practicing its questions. For now, we can start with these:
1. Binary Search
2. Merge Sort
3. Quick Sort
4. Fibonacci Series
5. Number Factors / Coin Change Problem
6. House Robber
7. Minimum Edit Distance problem
8. 0/1 Knapsack problem [Note: Fractional Knapsack is Greedy problem, 0/1 Knapsack is DnC]
9. Longest Common Subsequence
10. Longest Palindromic Subsequence
11. Longest Palindromic Substring
12. Min Cost to reach the last cell (bottom-right) from the first cell (top-left) in a 2D array
13. Number of possible paths from the first cell (top-left) to the last cell (bottom-right) in a 2D array
Comments
Post a Comment