ImageVerifierCode 换一换
格式:PPT , 页数:22 ,大小:361KB ,
资源ID:7281987      下载积分:10 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.docduoduo.com/d-7281987.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录   微博登录 

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(贪婪策略算法设计与分析.ppt)为本站会员(lxhqcj)主动上传,道客多多仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知道客多多(发送邮件至docduoduo@163.com或直接QQ联系客服),我们立即给予删除!

贪婪策略算法设计与分析.ppt

1、Greedy Strategy,Algorithm : Design & Analysis 15,In the last class,Undirected and Symmetric Digraph UDF Search Skeleton Biconnected Components Articulation Points and Biconnectedness Biconnected Component Algorithm Analysis of the Algorithm,Greedy Strategy,Optimization Problem MST Problem Prims Algo

2、rtithm Kruskals Algorithm Single-Source Shortest Path Problem Dijstras Algorithm Greedy Stretegy,Optimizing by Greedy,Coin Change Problem candidatesA finite set of coins, of 1, 5, 10 and 25 units, with enough number for each value constraintsPay an exact amount by a selected set of coins optimizatio

3、na smallest possible number of coins in the selected set Solution by greedy strategy For each selection, choose the highest-valued coin as possible.,Greedy Strategy,Constructing the final solution by expanding the partial solution step by step, in each of which a selection is made from a set of cand

4、idates, with the choice made must be: feasible it has to satisfy the problems constraints locally optimal it has to be the best local choice among all feasible choices on the step irrevocable the candidate selected can never be de-selected on subsquent steps,set greedy(set candidate)set S=;while not

5、 solution(S) and candidateselect locally optimazing x from candidate;candidate=candidate-x;if feasible(x) then S=Sx;if solution(S) then return Selse return (“no solution”),Greedy Fails Sometimes,If the availabe coins are of 1,5,12 units, and we have to pay 15 units totally, then the smallest set of

6、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.,Weighted Graph and MST,27,26,42,21,21,53,25,33,28,36,18,17,34,29,22,A,I,H,J,E,C,B,G,F,D,16,27,26,42,21,21,53,25,33,28,36,18,17,34,29,22,A,I,H,J,E,C,B,G,F,D,16,27,26,42,21,21,

7、53,25,33,28,36,18,17,34,29,22,A,I,H,J,E,C,B,G,F,D,16,A weighted graph The nearest neighbor of vertex I is H The nearest neighbor of shaded subset of vertex is G,21,21,21,25,25,25,A Spanning Tree: W(T)=257,A MST: W(T)=190,Graph Traversal and MST,There are cases that graph traversal tree cannot be min

8、imum spanning tree, with the vertices explored in any order.,1,1,1,1,1,All other edges with weight 5,DFS tree,BFS tree,in any ordering of vertex,Merging Two Vertices,v0,v6,v2,v5,v4,v1,v3,v6,v2,v5,v4,v3,v0,v6,v5,v4,v3,v0”,Constructing a Spanning Tree,a,b,c,d,a,a,a,b,b,b,c,c,c,d,d,d,0. Let a be the st

9、arting vertex, selecting edges one by one in original R 1. Merging a and c into a(a,c), selecting (a,c) 2. Merging a and b into a”(a,c,b), selecting (c,b) 3. Merging a” and d into a”(a,c,b,d), selecting (a,d) or (d,b) Ending, as only one vertex left,(0),(1),(2),(3),Prims Algorithm for MST,A,B,I,F,G,

10、H,C,E,D,2,3,4,1,2,1,5,6,7,4,2,8,2,6,3,edges included in the MST,Greedy stretegy: For each set of fringe vertex, select the edge with the minimal weight, that is, local optimal.,Minimum Spanning Tree Property,A spanning tree T of a connected, weighted graph has MST property if and only if for any non

11、-tree edge uv, Tuv contain a cycle in which uv is one of the maximum-weight edge. All the spanning trees having MST property have the same weight. For any two spanning tree T1 and T2 having MST property, let k be the number of edges that are in T1 but not in T2. When k=0, both trees have the same we

12、ight triavially. If k0, select an minimum-weight edge uv, say in T2 but not in T1, then T1uv has a cycle, in which there must be an edge, say, wiwi+1, with the same weight as uv, and not in T2. Exchange the two edge, we get a new spanning tree with less different edges from that of T1, but with the

13、same weight as T2. By induction, T1 and T2 has the same weight.,Minimum Spanning Tree Property,A spanning tree T of a connected, weighted graph has MST property if and only if for any non-tree edge uv, Tuv contain a cycle in which uv is one of the maximum-weight edge. All the spanning trees having M

14、ST property have the same weight.,u,v,edge uv in T2 but not in T1 , with minimum weight among all different edges,wi,wi+1,uv-path in T1,u,v,wi,wi+1,not in T2,edge exchange,a new spanning tree: same weight as T1, less different edges from that of T2,Must have same weight,MST Property and Minimum Span

15、ning Tree,In a connected, weighted graph G=(V,E,W), a tree T is a minimum spanning tree if and only if T has the MST property. Proor For a minimum spanning tree T, if it doesnt has MST property. So, there is a non-tree edge uv, and Tuv contain an edge xy with weight larger than that of uv. Substitut

16、ing uv for xy results a spanning tree with less weight than T. Contradiction. As claimed above, any minimum spanning tree has the MST property. Since T has MST property, it has the same weight as any minimum spanning tree, i.e. T is a minimum spanning tree as well.,Note: w(uiv)w(u1v), and if wa adde

17、d earlier than wb, then wa added later than any edges in u1wa-path, and v as well,Correctness of Prims Algorithm,Let Tk be the tree constructed after the kth step of Prims algorithm is excuted, then Tk has the MST property in Gk, the subgraph of G induced by vertices of Tk.,wa+1,wb-1,wa,wb,v, added

18、in Tk,Tk-1,edge added in Tk,u1(w1),ui(wp),added in Tk to form a cycle, only these need be considered,assumed first and last edges with larger weight than w(uiv), resulting contradictions.,Implementing Prims Algorithm,Main Procedure primMST(G,n)Initialize the priority queue pq as empty;Select vertex

19、s to start the tree;Set its candidate edge to (-1,s,0);insert(pq,s,0);while (pq is not empty)v=getMin(pq); deleteMin(pq);add the candidate edge of v to the tree;updateFringe(pq,G,v);return,Updating the Queue updateFringe(pq,G,v)For all vertices w adjcent to v /2m loopsnewWgt=w(v,w);if w.staturs is u

20、nseen thenSet its candidate edge to (v,w,newWgt);insert(pq,w,newWgt)else if newWgtgetPriorty(pq,w)Revise its candidate edge to (v,w,newWgt);decreaseKey(pq,w,newWgt)return,getMin(pq) always be the vertex with the smallest key in the fringe set.,ADT operation executions: insert, getMin, deleteMin: n t

21、imes getPriority: m times,Prims Algorithm for MST,A,B,I,F,G,H,C,E,D,2,3,4,1,2,1,5,6,7,4,2,8,2,6,3,edges included in the MST,Greedy stretegy: For each set of fringe vertex, select the edge with the minimal weight, that is, local optimal.,Complexity of Prims Algorithm,DecreaseKey operation will be exe

22、cuted m times. It is reasonably assumed that each decreaseKey is in O(1) DeleteMin operation will be executed n times, and each cost at worst in O(n), depending on the implementation The time complexity is in O(n2+m), which is O(n2) The lower bound of the MST problem is (m), since each edge must be

23、checked at least once. Note: m is in O(n2),Kruskals Algorithm for MST,A,B,I,F,G,H,C,E,D,2,3,4,1,2,1,5,6,7,4,2,8,2,6,3,edges included in the MST,Also Greedy stretegy: 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

24、 another sense.,Single Source Shortest Paths,s,7,7,2,1,2,3,1,2,4,4,8,3,5,3,4,6,5,0,1,2,6,6,4,3,9,The single source,Note: The shortest 0, 3-path doesnt contain the shortest edge leaving s, the edge 0,1,Red labels on each vertex is the length of the shortest path from s to the vertex.,Dijstras Algorithm: an Example,s,7,7,2,1,2,5,1,2,4,4,8,3,5,3,4,6,3,0,2,1,8,4,4,7,3,9,6,6,Home Assignment,pp.416-: 8.7-8.9 8.14-15 8.25,

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报