Divide and Conquer
来源:互联网 发布:哥们傲剑数据 编辑:程序博客网 时间:2024/06/10 13:13
Divide and Conquer
- Divide the problem (instance) into one or more sub-problems.
- Conquer each sub-problems recursively
- Combine solutions
Running Time:
(n/2) is the size of sub-problems.
2 is the number of sub-problems.
Binary Search
find x in sorted array.
1. Divide : comparex with middle
2. Conquer : recurse in one sub-array
3. Combine :trivial
Powering a number
given number x and integer n
Naive algorithm:
Divide-and-conquer algorithm(recursive squaring):
T(n) =
Fibonacci numbers
Bottom-up algorithm
Compare
Time:
Naive recursive squaring
So T(n)=
For some reasons, this algorithm can not be realized in practice.
Recursive squaring
Theorem
T(n)=
Matrix multiplication
Input: A=[
i,j=1,2…,n
Output:C=[
Standard algorithm
Computing every element in the matrix takes
Idea:
n∗n matrix=2∗2 block matrix
of n/2*n/2 sub-matrixes
C=[rtsu] =[acbd] *[egfh]
A=[acbd] B=[egfh]
8 recursive multiplications of n/2-by-n/2 matrixes
4 additions
Strassen’s algorithm
Idea:Reduce multiplication
p1=a(f-c)
p2=(a+b)h
p3=(c+d)e
p4=d(g-e)
p5=(a+d)(e+h)
p6=(b-d)(g+h)
p7=(a-c)(e+f)
r=p5+p4-p2+p6
s=p1+p2
t=p3+p4
u=p5+p1-p3-p7
“`
- Divide A B compute terms for products (a bunch of additions and subtractions) -
Θ(n2) - Conquer by recursively each
pi - Combine r,s,t,u -
Θ(n2)
VLSI layout
Problem: Embed a complete binary tree on n leaves in a grid with minimum area.
The vertices have to be embedded onto dots on the grid.
These edges have to be routed as sort of orthogonal paths between one dot and another.
Naive embedding
H(n)=H(n/2)+
W(n)=2W(n/2)+
Area(n)=
H-layout
Goal:W(n)=
Length(n)=2Length(n/4)+O(1)=
Area(n)=
- 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
- Android应用中通过AIDL机制实现进程间的通讯实例
- PHP7与Apache2.4关联配置
- 循序渐进学java基础笔记(4) —— 编译和java程序的运行关系
- iOS打包导出时出现Missing iOS Distribution signing identity问题
- 四元数计算
- Divide and Conquer
- 深入分析ConcurrentHashMap
- 巧用 div 层次 和 巧用百分比
- Mahout实现基于性别的IDRescorer
- php laravel5.1配置redis
- Storm本地模式环境问题
- 7zip的用法
- Java并发编程:并发容器之ConcurrentHashMap
- SQL 查询横表变竖表