Open In App

Divide and Conquer Algorithm

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

Divide and Conquer algorithm 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 Algorithm?

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 Algorithm:

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 Algorithm:

  • 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 Algorithm:

Standard Algorithms on Divide and Conquer Algorithm:

Binary Search based problems:

Practice problems on Divide and Conquer Algorithm:

Quick Links :



Similar Reads

Difference between Greedy Algorithm and Divide and Conquer Algorithm
Greedy algorithm and divide and conquer algorithm are two common algorithmic paradigms used to solve problems. The main difference between them lies in their approach to solving problems. Greedy Algorithm:The greedy algorithm is an algorithmic paradigm that follows the problem-solving heuristic of making the locally optimal choice at each stage wit
3 min read
Karatsuba algorithm for fast multiplication using Divide and Conquer algorithm
Given two binary strings that represent value of two integers, find the product of two strings. For example, if the first bit string is "1100" and second bit string is "1010", output should be 120. For simplicity, let the length of two strings be same and be n. A Naive Approach is to follow the process we study in school. One by one take all bits o
15+ min read
Comparison among Greedy, Divide and Conquer and Dynamic Programming algorithm
Greedy algorithm, divide and conquer algorithm, and dynamic programming algorithm are three common algorithmic paradigms used to solve problems. Here's a comparison among these algorithms: Approach:Greedy algorithm: Makes locally optimal choices at each step with the hope of finding a global optimum.Divide and conquer algorithm: Breaks down a probl
4 min read
Search in a Row-wise and Column-wise Sorted 2D Array using Divide and Conquer algorithm
Given an n x n matrix, where every row and column is sorted in increasing order. Given a key, how to decide whether this key is in the matrix. A linear time complexity is discussed in the previous post. This problem can also be a very good example for divide and conquer algorithms. Following is divide and conquer algorithm.1) Find the middle elemen
15+ min read
Closest Pair of Points using Divide and Conquer algorithm
We are given an array of n points in the plane, and the problem is to find out the closest pair of points in the array. This problem arises in a number of applications. For example, in air-traffic control, you may want to monitor planes that come too close together, since this may indicate a possible collision. Recall the following formula for dist
15+ min read
Maximum Subarray Sum using Divide and Conquer algorithm
You are given a one dimensional array that may contain both positive and negative integers, find the sum of contiguous subarray of numbers which has the largest sum. For example, if the given array is {-2, -5, 6, -2, -3, 1, 5, -6}, then the maximum subarray sum is 7 (see highlighted elements). Recommended: Please solve it on “PRACTICE ” first, befo
12 min read
Tiling Problem using Divide and Conquer algorithm
Given a n by n board where n is of form 2k where k >= 1 (Basically n is a power of 2 with minimum value as 2). The board has one missing cell (of size 1 x 1). Fill the board using L shaped tiles. A L shaped tile is a 2 x 2 square with one cell of size 1x1 missing. Figure 1: An example inputThis problem can be solved using Divide and Conquer. Bel
15+ min read
Longest Common Prefix using Divide and Conquer Algorithm
Given a set of strings, find the longest common prefix. Examples: Input : {“geeksforgeeks”, “geeks”, “geek”, “geezer”} Output : "gee" Input : {"apple", "ape", "april"} Output : "ap" We have discussed word by word matching and character by character matching algorithms.In this algorithm, a divide and conquer approach is discussed. We first divide th
7 min read
Convex Hull using Divide and Conquer Algorithm
In computational geometry, a convex hull is the smallest convex polygon that contains a given set of points. It is a fundamental concept with applications in various fields such as computer graphics, robotics, and image processing. Importance of Convex Hull:Convex hulls are important in computational geometry for several reasons: Collision detectio
15 min read
Advantages and Disadvantages of Divide and Conquer Algorithms
Divide and Conquer is an algorithmic paradigm in which the problem is solved using the Divide, Conquer, and Combine strategy. A typical divide-and-conquer algorithm solves a problem using the following three steps: Divide: This involves dividing the problem into smaller sub-problems.Conquer: Solve sub-problems by calling recursively until solved.Co
2 min read
Article Tags :
Practice Tags :