What is divide and conquer algorithm

What is divide and conquer algorithm?

1. Introduction

在这里插入图片描述

Divide and conquer is an algorithm design paradigm that recursively breaks down a problem into two or more subproblems of the same or related type, until these become simple enough to be solved directly. The solutions to the sub-problems are then combined to give a solution to the original problem. This technique can be divided into three parts: divide, conquer, and combine. The divide-and-conquer technique is the basis of efficient algorithms for many problems, such as sorting (e.g., quicksort, merge sort), multiplying large numbers (e.g., the Karatsuba algorithm), finding the closest pair of points, syntactic analysis (e.g., top-down parsers), and computing the discrete Fourier transform (FFT). 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.

  • Combine: Combine the sub-problems to get the final solution to the whole problem.

Divide and Conquer should be used when the same subproblems are not evaluated many times. Otherwise, Dynamic Programming or Memoization should be used. Divide and Conquer algorithms are used in multi-processor machines having shared-memory systems where the communication of data between processors does not need to be planned in advance because distinct sub-problems can be executed on different processors.


2. Characteristic

在这里插入图片描述

The divide-and-conquer paradigm is often used to find an optimal solution to a problem. Its basic idea is to decompose a given problem into two or more similar but simpler subproblems, solve them in turn, and compose their solutions to solve the given problem. Problems of sufficient simplicity are solved directly. For example, to sort a given list of n natural numbers, split it into two lists of about n/2 numbers each, sort each of them in turn, and interleave both results appropriately to obtain the sorted version of the given list. This approach is known as the merge sort algorithm.

The divide-and-conquer paradigm often helps in the discovery of efficient algorithms. It was the key, for example, to Karatsuba’s fast multiplication method, the quicksort and mergesort algorithms, the Strassen algorithm for matrix multiplication, and fast Fourier transforms. In all these examples, the divide-and-conquer approach led to an improvement in the asymptotic cost of the solution. For example, if the base cases have constant-bounded size, the work of splitting the problem and combining the partial solutions is proportional to the problem’s size n, and there is a bounded number p of sub-problems of size ~ n/p at each stage, then the cost of the divide-and-conquer algorithm will be O(n log p n).

The complexity for the multiplication of two matrices using the naive method is O(n^3), whereas using the divide and conquer approach (i.e., Strassen’s matrix multiplication) is O(n^2.8074). This approach also simplifies other problems, such as the Tower of Hanoi.


3. Example

在这里插入图片描述

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

  • Quicksort is a sorting algorithm. The algorithm 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[4].

  • Merge Sort is also a sorting algorithm. The algorithm divides the array into two halves, recursively sorts them, and finally merges the two sorted halves[4].

  • Closest Pair of Points: The problem is to find the closest pair of points in a set of points in the x-y plane. The problem can be solved in O(n^2) time by calculating the distances of every pair of points and comparing the distances to find the minimum. The Divide and Conquer algorithm solves the problem in O(N log N) time[4].

  • Strassen’s Algorithm is an efficient algorithm to multiply two matrices. A simple method to multiply two matrices needs 3 nested loops and is O(n^3). Strassen’s algorithm multiplies two matrices in O(n^2.8974) time[4].

  • Cooley-Tukey Fast Fourier Transform (FFT) algorithm is the most common algorithm for FFT. It is a divide and conquer algorithm that works in O(N log N) time[4].

  • Karatsuba algorithm for fast multiplication does the multiplication of two n-digit numbers in at most single-digit multiplications in general (and exactly when n is a power of 2). It is, therefore, faster than the classical algorithm, which requires n^2 single-digit products.


4. Summary

Divide and conquer is an algorithmic paradigm that solves a problem using the Divide, Conquer, and Combine strategy. First, the problem is divided into smaller sub-problems. Second, these sub-problems are solved by calling recursively until solved. Finally, the sub-problems are combined to get the final solution of the whole problem. This technique is used in many problems such as sorting, multiplying large numbers, finding the closest pair of points, syntactic analysis, and computing the discrete Fourier transform. It is often used to find an optimal solution to a problem by decomposing it into two or more similar, but simpler, subproblems, solving them in turn, and composing their solutions to solve the original problem. Some standard algorithms that use the Divide and Conquer algorithm are Merge Sort, Binary Search, Strassen’s Algorithm, Closest Pair of Points, Cooley-Tukey Fast Fourier Transform, and Karatsuba algorithm for fast multiplication.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值