Introduction to Divide and Conquer Algorithm (original) (raw)

Last Updated : 06 Mar, 2025

**Divide and Conquer **Algorithm is a problem-solving technique used to solve problems by dividing the main problem into subproblems, solving them individually and then merging them to find solution to the original problem. Divide and Conquer is mainly useful when we divide a problem into independent subproblems. If we have overlapping subproblems, then we use Dynamic Programming.

In this article, we are going to discuss how Divide and Conquer Algorithm is helpful and how we can use it to solve problems.

Working of Divide and Conquer Algorithm

Divide and Conquer Algorithm can be divided into three steps: **Divide, Conquer and **Merge.

Working-of-Divide-and-Conquer-Algorithm

The above diagram shows working with the example of Merge Sort which is used for sorting

**1. Divide:

In Merge Sort, we divide the input array in two halves. Please note that the divide step of Merge Sort is simple, but in Quick Sort, the divide step is critical. In Quick Sort, we partition the array around a pivot.

**2. Conquer:

In Merge Sort, the conquer step is to sort the two halves individually.

3. Merge:

In Merge Sort, the merge step is to merge two sorted halves to create one sorted array. Please note that the merge step of Merge Sort is critical, but in Quick Sort, the merge step does not do anything as both parts become sorted in place and the left part has all elements smaller (or equal( than the right part.

Characteristics of Divide and Conquer Algorithm

Divide and Conquer Algorithm involves breaking down a problem into smaller, more manageable parts, solving each part individually, and then combining the solutions to solve the original problem. The characteristics of Divide and Conquer Algorithm are:

**Examples of Divide and Conquer Algorithm

**1. Merge Sort:

We can use Divide and Conquer Algorithm to sort the array in ascending or descending order by dividing the array into smaller subarrays, sorting the smaller subarrays and then merging the sorted arrays to sort the original array.

Read more about Merge Sort

**2. Quicksort:

It is a sorting algorithm that picks a pivot element and rearranges the array elements so that all elements smaller than the picked pivot element move to the left side of the pivot, and all greater elements move to the right side. Finally, the algorithm recursively sorts the subarrays on the left and right of the pivot element.

Read more about Quick Sort

Complexity Analysis of Divide and Conquer Algorithm

T(n) = aT(n/b) + f(n), where n = size of input a = number of subproblems in the recursion n/b = size of each subproblem. All subproblems are assumed to have the same size. f(n) = cost of the work done outside the recursive call, which includes the cost of dividing the problem and cost of merging the solutions

Applications of Divide and Conquer Algorithm

The following are some standard algorithms that follow Divide and Conquer algorithm:

Introduction-to-Divide-and-Conquer-Algorithm-(1)

Advantages of Divide and Conquer Algorithm

**Disadvantages of Divide and Conquer Algorithm