Getting Started with Divide and Conquer Algorithms
In Chapter 2, Sorting Algorithms and Fundamental Data Structures, we introduced, among other sorting algorithms, merge and quick sort. A peculiarity of both algorithms is that they divide the problem into subproblems that are smaller instances of the same, solve each one of the subproblems recursively, and then combine the solutions to the subproblems into the solution for the original problem. This strategy forms the basis of the divide and conquer paradigm.
The Divide and Conquer Approach
In a divide and conquer approach, we solve a problem recursively, applying the following three steps at each level of recursion:
- Divide the problem into more than one subproblems that are smaller instances of the same problem.
- Conquer the subproblems by solving them recursively. Eventually, the subproblem sizes are small enough for them to be solved in a straightforward manner.
- Combine the solutions to the subproblems in the solution for the original problem...