Open In App

Divide and Conquer

Last Updated : 05 Apr, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Divide and Conquer is a problem-solving strategy that involves breaking down a complex problem into smaller, more manageable parts, solving each part individually, and then combining the solutions to solve the original problem. It is a widely used algorithmic technique in computer science and mathematics.

Example: In the Merge Sort algorithm, the “Divide and Conquer” strategy is used to sort a list of elements. Below image illustrate the dividing and merging states to sort the array using Merge Sort.

Divide-and-Conquer-banner

What is Divide and Conquer?

Divide and Conquer is a problem-solving technique that involves breaking a larger problem into subproblems, solving the subproblems independently and combining the solutions of those subproblems to get the solution of the larger problem.

Stages of Divide and Conquer:

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

1. Divide:

  • Break down the original problem into smaller subproblems.
  • Each subproblem should represent a part of the overall problem.
  • The goal is to divide the problem until no further division is possible.

2. Conquer:

  • Solve each of the smaller subproblems individually.
  • If a subproblem is small enough (often referred to as the “base case”), we solve it directly without further recursion.
  • The goal is to find solutions for these subproblems independently.

3. Merge:

  • Combine the sub-problems to get the final solution of the whole problem.
  • Once the smaller subproblems are solved, we recursively combine their solutions to get the solution of larger problem.
  • The goal is to formulate a solution for the original problem by merging the results from the subproblems.

Applications of Divide and Conquer:

  • Merge Sort: Merge sort is a classic example of a divide and conquer sorting algorithm. It breaks down the array into smaller subarrays, sorts them individually, and then merges them to obtain the sorted array.
  • Median Finding: The median of a set of numbers can be found using a divide and conquer approach. By recursively dividing the set into smaller subsets, the median can be determined efficiently.
  • Min and Max finding: Divide and Conquer algorithm can be used to find both the minimum and maximum elements in an array simultaneously. By splitting the array into halves and comparing the min-max pairs from each half, the overall min and max can be identified in logarithmic time complexity.
  • Matrix Multiplication: Strassen’s algorithm for matrix multiplication is a divide and conquer technique that reduces the number of multiplications required for large matrices by breaking down the matrices into smaller submatrices and combining their products.
  • Closest Pair problem: The closest pair problem involves finding the two closest points in a set of points in a multidimensional space. A divide and conquer algorithm, such as the “divide and conquer closest pair” algorithm, can efficiently solve this problem by recursively dividing the points and merging the solutions from the subproblems.

Basics of Divide and Conquer:

Standard Algorithms on Divide and Conquer:

Binary Search based problems:

Practice problems on Divide and Conquer:

Quick Links :



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads