Divide-and-Conquer
来源:互联网 发布:电子黑板软件 编辑:程序博客网 时间:2024/05/15 04:07
分治通常是用来降低用暴力解法已经能达到多项式时间复杂度的时间复杂度,结合randomization technique是powerful。
- Divide a problem into a number of independent sub-problems
- Conquer the subproblems by solving them recursively;
- Combine the solutions to the subproblems into the solution to the original problem;
复杂度分析
可分
问题的数据结构为:有相同的结构,但是smaller
- An array with n elements;
- A matrix;
- A set of n elements;
- A tree;
- A directed acyclic graph;
- A general graph;
sort
InsertionSort:Divide n element into a n−1-length array and an element
MergeSort:Divide into two halves
QuickSort:divide according to a randomly-selected pivot
随机选择pivot,会出现最坏情况pivot把number全部分到一个集合里,最好情况是各分一半,大多数情况pivot是nearly-central
为了使pivot基本分成2半,可以让算法强行选择一个比较合适的pivot,适用于distinct number,比上面的方法更慢。
由于大多数的pivot都是good,所以randomly选择pivot的时间复杂度是
Lomuto’s implementation
Hoare’s implementation [1961]
前面的方法对于distinc item是有效的,但是当有许多重复元素时,可考虑将元素分成3parts。
Selection:select the k-th smallest items in an array
pivot的选择会导致不同的时间复杂度,当选择median或者nearly-central时是(n),否则为
CountingInversion: to count inversions in an array of n integers
可以将CountingInversion问题当成排序问题。
MatrixMultiplication
通过减少子问题个数降低时间复杂度
ClosestPair problem
如果在一维直线上,通过排序可以得到最近点对。
二维平面上先按照x排序,等分成2部分。
- Divide and conquer algorithm
- Divide-and-Conquer
- 分治 Divide and Conquer
- divide-and-conquer
- algorithm:divide and conquer
- Divide and Conquer
- Divide and Conquer
- Divide and conquer
- divide and conquer
- Divide and Conquer
- [leetcode] Divide and Conquer
- Divide and Conquer
- Divide and Conquer
- Divide and conquer 总结
- leetcode-Divide and Conquer
- LeetCode--Divide and Conquer
- Divide and Conquer
- Divide-and-Conquer
- 银行和企业奋力打击Bash Shellshock 漏洞
- easyui选中行删除后,无法释放选中状态
- js中正则表达式的理解(一)
- 双十一只是在搞噱头么?看看ABBYY FineReader就知道了
- matlab 反复激活 许可证到期 解决方法
- Divide-and-Conquer
- 我们来看ViewRootImpl的构造函数
- mt2503[AT Command]更改PDP context命令CGCMOD用法说明
- MFC实现256色工具栏图标及工具栏提示信息
- 安迪比尔定理
- JS汉字转拼音
- android studio中程序崩溃无法查看log
- RGB转为16进制
- 读书笔记-PHP、MySQL与JavaScript学习手册