110 likes | 286 Views
计算机问题求解. 解 题的一些基本策略. 问题讨论 - 1. 什么是“ algorithmic method”, 它在问题求解中有什么意义?. 问题讨论 - 2. 你 是 否 熟 悉 什 么“ algorithmic method ”,能不能举个例子说明某种方法?. 问题讨论 - 3. Greedy method: 它的力量和弱点是什么? 例子:简单而有效:最小生成树 例子:难以判断对与错:硬币问题 例 子:对很难的问题也能有作用. Kruskal’s Algorithm for MST. 2. B. Also Greedy strategy:
E N D
计算机问题求解 解题的一些基本策略
问题讨论 -1 • 什么是“algorithmic method”, 它在问题求解中有什么意义?
问题讨论 -2 • 你是否熟悉什么“algorithmic method”,能不能举个例子说明某种方法?
问题讨论 -3 • Greedy method: 它的力量和弱点是什么? • 例子:简单而有效:最小生成树 • 例子:难以判断对与错:硬币问题 • 例子:对很难的问题也能有作用
Kruskal’s Algorithm for MST 2 B Also Greedy strategy: From the set of edges not yet included in the partially built MST, select the edge with the minimal weight, that is, local optimal, in another sense. A 6 3 4 7 G 3 1 5 F I H C 2 4 8 2 2 6 E D 1 edges included in the MST
Greedy Fails Sometimes • If the available coins are of 1,5,12 units, and we have to pay 15 units totally, then the smallest set of coins is {5,5,5}, but not {12,1,1,1} • However, the correctness of greedy strategy on the case of {1,5,10,25} is not straightly seen.
Next Fit Algorithm - NF • The strategy: Put a new item in the last bin if possible, or use a new bin. Never look back! • An example: S={0.2, 0.5, 0.4, 0.7, 0.1, 0.3, 0.8} 0.1 0.5 0.8 0.7 0.4 0.3 0.2
Simple, but Not So Bad • For a given S, if the optimal value is m, NF algorithm uses at most 2m bins. • Proof: • Note that no two consecutive bins can contain object with total value less than 1, which mean half space is wasted at most.
问题讨论 -4 • divide-and-conquer: 为什么很有效?
Quicksort: the Strategy • Dividing the array to be sorted into two parts: “small” and “large”, which will be sorted recursively. [first] [last] for any element in this segment, the key is not less than pivot. for any element in this segment, the key is less than pivot.
问题讨论 -5 • 集合运算的定理:为什么样子与逻辑运算很象?