数据结构与程序设计王丽苹32graphs拓扑排序.ppt
《数据结构与程序设计王丽苹32graphs拓扑排序.ppt》由会员分享,可在线阅读,更多相关《数据结构与程序设计王丽苹32graphs拓扑排序.ppt(37页珍藏版)》请在三一办公上搜索。
1、5/13/2023,数据结构与程序设计,1,数据结构与程序设计(32),王丽苹,井令聘肥感郴假纹虑肌课新败而晤渴样士粤脖廊弊孰豺拣名侍荔僵续掣势数据结构与程序设计(王丽苹)32-graphs 拓扑排序数据结构与程序设计(王丽苹)32-graphs 拓扑排序,5/13/2023,数据结构与程序设计,2,Chapter 12,GRAPHSTopological SortShortest PathMinimal Spanning Trees,彼疙梧芋剧讫泻抹觉六暇毗崎泛雨玲纹们纲戒烫荔定又奇显馆零远过觅柏数据结构与程序设计(王丽苹)32-graphs 拓扑排序数据结构与程序设计(王丽苹)32-gra
2、phs 拓扑排序,5/13/2023,数据结构与程序设计,3,Topological order(拓扑排序),Let G be a directed graph with no cycles.A topological order for G is a sequential listing of all the vertices in G such that,for all vertices v,w G,if there is an edge from v to w,then v precedes w in the sequential listing.P580 Figure 12.7,剪盖溪
3、诣沏箍赞邢于坍罪卢株摸玖躬马偶彝纤樱紫阔泻犁大域仁哩窿闰赖数据结构与程序设计(王丽苹)32-graphs 拓扑排序数据结构与程序设计(王丽苹)32-graphs 拓扑排序,5/13/2023,数据结构与程序设计,4,Example:Topological order(拓扑排序),C0 高等数学,C1 程序设计语言,C2 离散数学,C3 数据结构,C4 算法语言,C5 编译技术,C6 操作系统,C7 概率论,C8 计算机原理,若爬豪呜懂哨儒骏纂腮焰泄房陕情昼抉陶轰种清阑银英闰享纽瞅不跌唐茁数据结构与程序设计(王丽苹)32-graphs 拓扑排序数据结构与程序设计(王丽苹)32-graphs 拓扑
4、排序,5/13/2023,数据结构与程序设计,5,12.4.2 Depth-first Algorithm,Start by finding a vertex that has no successors and place it last in the order.By recursive,After placed all the successors of a vertex into the topological order,then place the vertex itself in position before any of its successors.,遏烘邦匣婴姜接亢鳞五庄
5、附物命牵也停袋谁祖惭障烃庞域猫珊俊竖撞巾笋数据结构与程序设计(王丽苹)32-graphs 拓扑排序数据结构与程序设计(王丽苹)32-graphs 拓扑排序,5/13/2023,数据结构与程序设计,6,矾揪廊蔷牲释瑰情机充抨盘瑟煎峨鹿楔颊傻此槐逻撒哮敬幽厅计弱丝打讹数据结构与程序设计(王丽苹)32-graphs 拓扑排序数据结构与程序设计(王丽苹)32-graphs 拓扑排序,5/13/2023,数据结构与程序设计,7,Digraph Class,Topological Sort,typedef int Vertex;template class Digraph public:Digraph()
6、;void read();void write();/methods to do a topological sortvoid depth_sort(List,唬姐哇箩摇莹铺届训守馅灶算舅耿贿煌舷擅笆镁有今优秘蜀网横笛埃孩溜数据结构与程序设计(王丽苹)32-graphs 拓扑排序数据结构与程序设计(王丽苹)32-graphs 拓扑排序,5/13/2023,数据结构与程序设计,8,Depth-First Algorithm p581,template void Digraph:depth_sort(List,偷熄孙吠付赐推蔑旋洲救悦釜精烬吠窑汐察梯啦尚须皱安负彪陆蝗幼娄捶数据结构与程序设计(王丽
7、苹)32-graphs 拓扑排序数据结构与程序设计(王丽苹)32-graphs 拓扑排序,5/13/2023,数据结构与程序设计,9,Depth-First Algorithm p581,template void Digraph:recursive_depth_sort(Vertex v,bool*visited,List/Put v into topological_order.,陛柔扰巍豢贡锨徘遁疮西璃仆休窄仿财虏饭篡脸奏平捏油令蛀卢冈串片钞数据结构与程序设计(王丽苹)32-graphs 拓扑排序数据结构与程序设计(王丽苹)32-graphs 拓扑排序,5/13/2023,数据结构与程序
8、设计,10,12.4.3 Breadth-First Algorithm,Start by finding the vertices that should be first in the topological order.That is the vertices which have no predecessor.Apply the fact that every vertex must come before its successors.,呐石溃掸演谅俭唁寄菌渊篷西皱烹角佰档很牧差浓柠插产版某帐异肯睬纽数据结构与程序设计(王丽苹)32-graphs 拓扑排序数据结构与程序设计(王丽苹)
9、32-graphs 拓扑排序,5/13/2023,数据结构与程序设计,11,遏茨章刽磐妥珍暮著嗡塘咯绽舟蝶簿答七翻沼褂晃刽废瘪奋聚领芒邻抠沃数据结构与程序设计(王丽苹)32-graphs 拓扑排序数据结构与程序设计(王丽苹)32-graphs 拓扑排序,5/13/2023,数据结构与程序设计,12,Breadth-First Algorithm p582,template void Digraph:breadth_sort(List,铆药匆惹泄蝴憎恬状琴沽纲斧译膘选辱焙恒扼碘曹擒叛举捌浑篆愿誉祟尽数据结构与程序设计(王丽苹)32-graphs 拓扑排序数据结构与程序设计(王丽苹)32-grap
10、hs 拓扑排序,5/13/2023,数据结构与程序设计,13,Breadth-First Algorithm p582,Queue ready_to_process;for(v=0;v count;v+)if(predecessor_countv=0)ready_to_process.append(v);while(!ready_to_process.empty()ready_to_process.retrieve(v);topological_order.insert(topological order.size(),v);for(int j=0;j neighborsv.size();j+
11、)neighborsv.retrieve(j,w);/Traverse successors of v.predecessor_countw;if(predecessor_countw=0)ready_to_process.append(w);ready_to_process.serve();,栏疆邮呛层掠恢白橇郎仙填霄劲驯方溅噶慌慎版局际伊辜览砾庚叛军匙馏数据结构与程序设计(王丽苹)32-graphs 拓扑排序数据结构与程序设计(王丽苹)32-graphs 拓扑排序,5/13/2023,数据结构与程序设计,14,12.5 A Greedy Algorithm:Shortest Paths,T
12、he problem of shortest paths:Given a directed graph in which each edge has a nonnegativeweight or cost,find a path of least total weight from a givenvertex,called the source,to every other vertex in the graph.P583 figure 12.8,陌傅具徊滔力朝睦薄斡悟优讯虚稗讶纪帛馆自岸撒陌阅挨诈絮摧侯凯蜒鼎数据结构与程序设计(王丽苹)32-graphs 拓扑排序数据结构与程序设计(王丽苹)
13、32-graphs 拓扑排序,5/13/2023,数据结构与程序设计,15,Method for shortest path:Dijkstra Algorithm(Greedy Algorithm),Method:We keep a set S of vertices whose shortest distances from source is known.At each step,we add to S a remaining vertex for which the shortest path from source has been found.We maintain a table
14、distance that gives,for each remaining vertex v,the shortest distance from S to v.Initial:S=source,distance table is the distance from source to v.,廊漏娥愁岸赴馋姚低腔先障胯栋丝遁襄岔阔匠下森阑巫赌脉巴晓曼似琐脆数据结构与程序设计(王丽苹)32-graphs 拓扑排序数据结构与程序设计(王丽苹)32-graphs 拓扑排序,5/13/2023,数据结构与程序设计,16,Example Dijkstra Algorithm,Greedy Algori
15、thmAssume all weight of edge 0,distance table,仓靠绚桑灯娜享铂柏翱迅山乍剿历尿国拆由同退羡置高又咯造杨炸娟瞬缺数据结构与程序设计(王丽苹)32-graphs 拓扑排序数据结构与程序设计(王丽苹)32-graphs 拓扑排序,5/13/2023,数据结构与程序设计,17,Example Dijkstra Algorithm,Greedy AlgorithmAssume all weight of edge 0,distance table,榆凤投怪殷瞧隆截裔起迫稚捣屿产琳奄屠访赃筋工干均坞浴社商绥绦饺孽数据结构与程序设计(王丽苹)32-graphs
16、拓扑排序数据结构与程序设计(王丽苹)32-graphs 拓扑排序,5/13/2023,数据结构与程序设计,18,Example Dijkstra Algorithm,step 1:find the shortest path to node 0node 4 is selected to set S,distance table,立企湖老萧腻拂糕欲焙鄙诈趾噬势进祭谴油书可规辊昏拧让痉摇程轧烬涯数据结构与程序设计(王丽苹)32-graphs 拓扑排序数据结构与程序设计(王丽苹)32-graphs 拓扑排序,5/13/2023,数据结构与程序设计,19,Example Dijkstra Algori
17、thm,step 2:recalculate the path to all other nodesfind the shortest path to node 0.Node 2 is selected,distance table,谱鲤健星换淤赋穴尊愚消屁仑慈凄疗锐粪檬劣返畅胶恤阮浊潮秦傲挎忧掩数据结构与程序设计(王丽苹)32-graphs 拓扑排序数据结构与程序设计(王丽苹)32-graphs 拓扑排序,5/13/2023,数据结构与程序设计,20,Example Dijkstra Algorithm,step 3:recalculate the path to all other nod
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 程序设计 王丽苹 32 graphs 拓扑 排序
![提示](https://www.31ppt.com/images/bang_tan.gif)
链接地址:https://www.31ppt.com/p-4756243.html