Understanding the Divide-and-Conquer Approach
At the core of the divide-and-conquer approach is a simple and intuitive idea: if you don't know how to solve a large instance of a problem, find a small part of the problem that you can solve, and then solve it. Then, iterate for more such parts, and once you have solved all the parts, combine the results into a large coherent solution to the original problem. There are three steps to solving a problem using the divide-and-conquer approach:
- Divide: Take the original problem and divide it into parts so that the same problem needs to be solved for each part.
- Conquer: Solve the problem for each part.
- Combine: Take the solutions for the different parts and combine them into a solution for the original problem.
In the previous section, we looked at an example of using divide and conquer to search within a sequence. At each step, binary search tries to search in only a part of the sequence, which is marked as the range. The search...