Divide and Conquer

Source: Internet
Author: User

Divide and Conquer is an algorithmic paradigm based on multi-branched recursion.
A typical Divide and Conquer algorithm solves a problem using following three steps:


1. Divide: Break the given problem into subproblems of same type.
2. Conquer: Recursively solve these subproblems
3. Combine: Appropriately combine the answers

 

 

The name "divide and conquer" is sometimes applied also to algorithms that reduce each problem to only one subproblem, such as the binary search algorithm.
Because it uses tail recursion, so it can be converted into simple loops. under this broad definition, however, every algorithm that uses recursion or loops cocould be regarded as a "divide and conquer algorithm ". therefore, some authors (I prefer this viewpoint too) consider that the name "divide and conquer" shocould be used only when each problem may generate two or more subproblems. the name decrease and conquer has been proposed instead for the single-subproblem class.


Divide and Conquer (D & C) vs Dynamic Programming (DP)
Both paradigms (D & C and DP) divide the given problem into subproblems and solve subproblems. How to choose one of them for a given problem? Divide and Conquer shocould be used when same subproblems are not evaluated frequently times. otherwise Dynamic Programming or Memoization shocould be used. for example, Quicksort is a Divide and Conquer algorithm, we never evaluate the same subproblems again. on the other hand, for calculating nth Fibonacci number, Dynamic Programming shoshould be preferred.

 

Following are some standard algorithms that are Divide and Conquer algorithms.

 


1) Quicksort is a sorting algorithm. the algorithm picks a random element, rearranges the array elements in such a way that all elements smaller than the picked partition element move to left side of memory, and all greater elements move to right side. finally, the algorithm recursively sorts the subarrays on left and right of each element.

 


2) Merge Sort is also a sorting algorithm. The algorithm divides the array in two halves, recursively sorts them and finally merges the two sorted halves.

 


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

 


5) Strassen's Algorithm is an efficient algorithm to multiply two matrices. A simple method to multiply two matrices need 3 nested loops and is O (n ^ 3 ). strassen's algorithm multiplies two matrices in O (n ^ 2.8974) time.

 


6) Cooley-Tukey Fast Fourier Transform (FFT) algorithm is the most common algorithm for FFT. It is a divide and conquer algorithm which works in O (nlogn) time.

 


5) Karatsuba algorithm for fast multiplication it does 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 n2 single-digit products. if n = 210 = 1024, in particle, the exact counts are 310 = 59,049 and (210) 2 = 1,048,576, respectively.

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.