How Divide and Conquer Algorithms
Work? Here are the steps involved:
1. Divide: Divide the given problem into sub-problems using recursion. 2.
Conquer: Solve the smaller sub-problems recursively. If the subproblem is
small enough, then solve it directly.
3. Combine: Combine the solutions of the sub-problems that are part of the
recursive process to solve the actual problem.
Here, we will sort an array using the divide and conquer approach (ie. merge
sort).
1. Let the given array be: Array for merge sort
2. Divide the array into two halves.
3. Divide the array into two subparts
Again, divide each subpart recursively into two halves until you get individual
elements.
Divide
the array into smaller subparts
4. Now, combine the individual elements in a sorted manner.
Here, conquer and combine steps go side by side.
Combine the subparts