欢迎来到优知文库! | 帮助中心 分享价值,成长自我!
优知文库
全部分类
  • 幼儿/小学教育>
  • 中学教育>
  • 高等教育>
  • 研究生考试>
  • 外语学习>
  • 资格/认证考试>
  • 论文>
  • IT计算机>
  • 法律/法学>
  • 建筑/环境>
  • 通信/电子>
  • 医学/心理学>
  • ImageVerifierCode 换一换
    首页 优知文库 > 资源分类 > PPT文档下载
    分享到微信 分享到微博 分享到QQ空间

    数据结构与程序设计王丽苹32graphs拓扑排序.ppt

    • 资源ID:468110       资源大小:1.06MB        全文页数:37页
    • 资源格式: PPT        下载积分:7金币
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    三方登录下载: QQ登录
    二维码
    扫码关注公众号登录
    下载资源需要7金币
    邮箱/手机:
    温馨提示:
    快捷下载时,如果您不填写信息,系统将为您自动创建临时账号,适用于临时下载。
    如果您填写信息,用户名和密码都是您填写的【邮箱或者手机号】(系统自动生成),方便查询和重复下载。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP,免费下载
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    数据结构与程序设计王丽苹32graphs拓扑排序.ppt

    9/8/2023数据结构与程序设计1数据结构与程序设计数据结构与程序设计(32)9/8/2023数据结构与程序设计2Chapter 12nGRAPHSnTopological SortnShortest PathnMinimal Spanning Trees9/8/2023数据结构与程序设计3Topological 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.79/8/2023数据结构与程序设计4Example:Topological order(拓扑排序)nC0 高等数学,C1 程序设计语言,C2 离散数学,C3 数据结构,C4 算法语言,C5 编译技术,C6 操作系统,C7 概率论,C8 计算机原理9/8/2023数据结构与程序设计512.4.2 Depth-first AlgorithmnStart by finding a vertex that has no successors and place it last in the order.nBy 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.9/8/2023数据结构与程序设计69/8/2023数据结构与程序设计7Digraph Class,Topological Sorttypedef int Vertex;template class Digraph public:Digraph();void read();void write();/methods to do a topological sortvoid depth_sort(List&topological_order);void breadth_sort(List&topological_order);private:int count;List neighborsgraph_size;void recursive_depth_sort(Vertex v,bool visited,List&topological_order);9/8/2023数据结构与程序设计8Depth-First Algorithm p581template void Digraph:depth_sort(List&topological_order)/*Post:The vertices of the Digraph are placed into List topological_order with adepth-first traversal of those vertices that do not belong to a cycle.Uses:Methods of class List,and function recursive_depth_sort to perform depth-first traversal.*/bool visitedgraph_size;Vertex v;for(v=0;v count;v+)visitedv=false;topological_order.clear();for(v=0;v count;v+)if(!visitedv)/Add v and its successors into topological order.recursive_depth_sort(v,visited,topological_order);9/8/2023数据结构与程序设计9Depth-First Algorithm p581template void Digraph:recursive_depth_sort(Vertex v,bool*visited,List&topological_order)/*Pre:Vertex v of the Digraph does not belong to the partially completed List topological_order.Post:All the successors of v and finally v itself are added to topological orderwith a depth-first search.Uses:Methods of class List and the function recursive_depth_sort.*/visitedv=true;int degree=neighborsv.size();for(int i=0;i degree;i+)Vertex w;/A(neighboring)successor of vneighborsv.retrieve(i,w);if(!visitedw)/Order the successors of w.recursive_depth_sort(w,visited,topological_order);topological_order.insert(0,v);/Put v into topological_order.9/8/2023数据结构与程序设计1012.4.3 Breadth-First AlgorithmnStart by finding the vertices that should be first in the topological order.That is the vertices which have no predecessor.nApply the fact that every vertex must come before its successors.9/8/2023数据结构与程序设计119/8/2023数据结构与程序设计12Breadth-First Algorithm p582template void Digraph:breadth_sort(List&topological_order)/*Post:The vertices of the Digraph are arranged into the List topological_orderwhich is found with a breadth-first traversal of those vertices that do not belongto a cycle.Uses:Methods of classes Queue and List.*/topological_order.clear();Vertex v,w;int predecessor_countgraph size;for(v=0;v count;v+)predecessor_countv=0;for(v=0;v count;v+)for(int i=0;i neighborsv.size();i+)neighborsv.retrieve(i,w);/Loop over all edges v-w.predecessor_countw+;9/8/2023数据结构与程序设计13Breadth-First Algorithm p582Queue 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 0node from node V0 to other nodesV1V2V3V4bestdistance table9/8/2023数据结构与程序设计17Example Dijkstra AlgorithmnGreedy AlgorithmnAssume all weight of edge 0node from node V0 to other nodesV15V23V3 V42bestV4distance table9/8/2023数据结构与程序设计18Example Dijkstra Algorithmnstep 1:find the shortest path to node 0nnode 4 is selected to set Snode from node V0 to other nodesV15V23V3 V42bestV4distance table9/8/2023数据结构与程序设计19Example Dijkstra Algorithmnstep 2:recalculate the path to all other nodesnfind the shortest path to node 0.Node 2 is selectednode from node V0 to other nodesV155V233V3 6V42bestV4V2distance table9/8/2023数据结构与程序设计20Example Dijkstra Algorithmnstep 3:recalculate the path to all other nodesnfind the shortest path to node 0.node 1 is selectednode from node V0 to other nodesV1554V233V3 65V42bestV4V2V1distance table9/8/2023数据结构与程序设计21Example Dijkstra Algorithmnstep 4:recalculate the path to all other nodesnfind the shortest path to node 0.node 3 is selectednode from node V0 to other nodesV1554V233V3 655V42bestV4V2V1V39/8/2023数据结构与程序设计22A Greedy Algorithm:Shortest Paths p587template class Digraph public:/Add a constructor and methods for Digraph input and output.void set_distances(Vertex source,Weight distance)const;protected:int count;Weight adjacencygraph_sizegraph_size;9/8/2023数据结构与程序设计23A Greedy Algorithm:Shortest Pathstemplate void Digraph:set_distances(Vertex source,Weight distance)const/*Post:The array distance gives the minimal path weight from vertex so

    注意事项

    本文(数据结构与程序设计王丽苹32graphs拓扑排序.ppt)为本站会员(王**)主动上传,优知文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知优知文库(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

    copyright@ 2008-2023 yzwku网站版权所有

    经营许可证编号:宁ICP备2022001189号-2

    本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。优知文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知优知文库网,我们立即给予删除!

    收起
    展开