动态规划是优化的分治,贪心的局部最优可能达成全局最优,而动规的最优值中不一定全是局部最优。
一. 分治法 :
1. divide and conquer , solve the problems by dividing it into two halves, solve the two halves, and put the solution together.
2. 通常是 top down paradigm
** 应用 **
mergesort:应用到递归
Binary search tree:应用到递归
二. 贪心算法:
1. 贪心选择性质
2. 最优子结构
3. 通常是Bottem up paradigm
** 应用 **
Prim’s algorithm { 每次选择距离当前生成树最近的节点}
Dijkstra algorithm { 每次选择距离source vertice 最近的节点}
Scheduling application { weight/length }
Huffman codes (prefix-free codes) { 每次选择两个frequency最小的alphabet }
三. 动态规划:
1. 重叠子问题
2. 最优子结构
3. 步骤 :
a) Identify a small number of subproblems
b) Can quickly correctly solve “large” subproblems given the solutions to “smaller subproblems”
(usually via a recurrence and the optimal solutions to a given subproblem is as a function
of the optimal solutions to smaller subproblems)
c) After solving all the sub problems, can quickly conpute the final solution
4. 细化步骤 :
a) 假设optimal solution 成立
b) 在假设成立的条件下,find the exactly several possibility of the last Item
c) Analyse several situation of deleting the last item, find optimal substructure
d) The recurrence
Brute force
for {
for {
{1.
A= min/max 2.
3.}
}
}
e) Implicit it from begin
** 应用 **:
The knapsack problem
Sequence alignment
Optimal binary search trees