博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Divide and Conquer
阅读量:4151 次
发布时间:2019-05-25

本文共 2968 字,大约阅读时间需要 9 分钟。

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  algorithm.
Because it uses , so it can be converted into simple . Under this broad definition, however, every algorithm that uses recursion or loops could be regarded as a "divide and conquer algorithm". Therefore, some authors (I prefer this viewpoint too) consider that the name "divide and conquer" should 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 should be used when same subproblems are not evaluated many times. Otherwise Dynamic Programming or Memoization should 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 should be preferred.

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

1)  is a sorting algorithm. The algorithm picks a pivot element, rearranges the array elements in such a way that all elements smaller than the picked pivot element move to left side of pivot, and all greater elements move to right side. Finally, the algorithm recursively sorts the subarrays on left and right of pivot element.

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

3)  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)  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)  is the most common algorithm for FFT. It is a divide and conquer algorithm which works in O(nlogn) time.

5)  it does multiplication of two n-digit numbers in at most 3 n^{\log_23}\approx 3 n^{1.585} single-digit multiplications in general (and exactly n^{\log_23} 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 particular, the exact counts are 310 = 59,049 and (210)2 = 1,048,576, respectively.

References

转载地址:http://hhxti.baihongyu.com/

你可能感兴趣的文章
栈和堆的空间大小 C++
查看>>
什么是缓冲区溢出 C++
查看>>
sizeof C++
查看>>
使用指针有哪些好处? C++
查看>>
引用还是指针?
查看>>
checkio-non unique elements
查看>>
checkio-medium
查看>>
checkio-house password
查看>>
checkio-moore neighbourhood
查看>>
checkio-the most wanted letter
查看>>
Redis可视化工具
查看>>
大牛手把手带你!2021新一波程序员跳槽季,全套教学资料
查看>>
JAVA自定义注解与通过反射去解析注解参数
查看>>
Effective Java学习(创建和销毁对象)之——通过私有化构造器强化不可实例化的能力...
查看>>
Effective Java学习(创建和销毁对象)之——消除过期对象引用
查看>>
Effective Java学习(泛型)之——消除非受检警告
查看>>
Effective Java学习(泛型)之——List列表优先于数组
查看>>
Effective Java学习(泛型)之——优先使用泛型化
查看>>
Effective Java学习(泛型)之——优先考虑泛型化方法
查看>>
Effective Java学习(方法)之——返回零长度的数组或者集合,而不是null
查看>>