Divide and Conquer Algorithm

Divide and Conquer approach basically works on breaking the problem into sub problems that are similar to the original problem but smaller in size & simpler to solve.

Once divided sub problems are solved recursively and then combine solutions of sub problems to create a solution to original problem.

At each level of the recursion the divide and conquer approach follows three steps:

  • Divide: In this step whole problem is divided into several sub problems.
  • Conquer: The sub problems are conquered by solving them recursively, only if they are small enough to be solved, otherwise step1 is executed.
  • Combine: In this final step, the solution obtained by the sub problems are combined to create solution to the original problem.
Divide and Conquer Algorithm

Generally, we can follow the divide and conquer approach in a three-step process.

Examples: The specific computer algorithms are based on the Divide & Conquer approach:

  1. Maximum and Minimum Problem
  2. Binary Search
  3. Sorting (merge sort, quick sort)
  4. Tower of Hanoi

Fundamental of Divide & Conquer Strategy:

There are two fundamentals of Divide & Conquer Strategy:

  1. Relational Formula
  2. Stopping Condition

1. Relational Formula:

It is the formula that we generate from the given technique. After generation of Formula, we apply D&C Strategy, i.e., we break the problem recursively & solve the broken subproblems.

2. Stopping Condition:

When we break the problem using Divide & Conquer Strategy, then we need to know that for how much time, we need to apply divide & Conquer. So, the condition where the need to stop our recursion steps of D&C is called as Stopping Condition.


Applications of Divide and Conquer Approach:

Following algorithms are based on the concept of the Divide and Conquer Technique:

Binary Search:

The binary search algorithm is a searching algorithm, which is also called a half-interval search or logarithmic search. It works by comparing the target value with the middle element existing in a sorted array. After making the comparison, if the value differs, then the half that cannot contain the target will eventually eliminate, followed by continuing the search on the other half.

We will again consider the middle element and compare it with the target value. The process keeps on repeating until the target value is met. If we found the other half to be empty after ending the search, then it can be concluded that the target is not present in the array.

Quick Sort:

It is the most efficient sorting algorithm, which is also known as partition-exchange sort. It starts by selecting a pivot value from an array followed by dividing the rest of the array elements into two sub-arrays.

The partition is made by comparing each of the elements with the pivot value. It compares whether the element holds a greater value or lesser value than the pivot and then sort the arrays recursively.

Merge Sort:

It is a sorting algorithm that sorts an array by making comparisons. It starts by dividing an array into sub-array and then recursively sorts each of them. After the sorting is done, it merges them back.


Advantages of Divide and Conquer

  • Divide and Conquer tend to successfully solve one of the biggest problems, such as the Tower of Hanoi, a mathematical puzzle. It is challenging to solve complicated problems for which you have no basic idea, but with the help of the divide and conquer approach, it has lessened the effort as it works on dividing the main problem into two halves and then solve them recursively.
  • This algorithm is much faster than other algorithms.
  • It efficiently uses cache memory without occupying much space because it solves simple subproblems within the cache memory instead of accessing the slower main memory.

Disadvantages of Divide and Conquer

  • Since most of its algorithms are designed by incorporating recursion, so it necessitates high memory management.
  • An explicit stack may overuse the space.
  • It may even crash the system if the recursion is performed rigorously greater than the stack present in the CPU.