- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
称为双连通成分biconnectedcomponent.PPT
鄰接矩陣 Adjacency Matrix Adjacency Matrix is a two dimensional n×n array. 0 3 1 2 0 1 2 (a) G1 (b) G2 Adjacency Matrix 0 3 1 2 4 7 5 6 G4 H1 H2 (c) G3 Depth-First Search 0 7 1 3 4 2 5 6 1 0 0 1 1 2 2 3 0 2 3 5 0 7 0 7 0 7 0 7 4 0 4 0 6 5 0 6 [0] [1] [2] [3] [4] [5] [6] [7] HeadNodes 0,1,3,7,4,5,2,6 DFS Algorithm Algorithm DFS(G, v) Input: A graph G and a vertx v of G Output: A labeling of the edges in the connected component of v as discovery edges and back edges for all edges e in G.incidentEdges(v) do if edge e is unexplored then w ? G.opposite(v, e) if vertax w is unexplored then label e as a discovery edge recursively call DFS(G, w) else label e as a back edge DFS 可以做什麼? 圖G 有n個頂點和 m 個邊,且使用連接串列表示的圖,則圖G 的DFS 走訪,可以在 O(n+m)完成,並可以解決以下問題 測試G是否連通 計算G的生成森林 計算G 的連通成分 計算G中兩頂點之間的路徑,或回報路徑不存在。 計算G中的一個迴路,或回報G沒有迴路。 A B C D E F G H I J K L M N O P 發現邊 返回邊 A B C D E F G H I J K L M 計算雙連通成分 EC DE CD CF KL HJ GH FG HI EC JG IF CM BC AB CK MA MB KA 計算雙連通成分演算法 參見課本 P315 及 P317 Breadth-First Search 0 7 1 3 4 2 5 6 1 0 0 1 1 2 2 3 0 2 3 5 0 7 0 7 0 7 0 7 4 0 4 0 6 5 0 6 [0] [1] [2] [3] [4] [5] [6] [7] HeadNodes 0,1,2,3,4,5,6,7 BFS Algorithm Algorithm BFS(G, v) Input: A graph G and a vertx s of G Output: A labeling of the edges in the connected component of s as discovery edges and cross edges create an empty container L0 insert s into L0 i ? 0 while Li is not empty do create an empty container Li+1 for each vertax v in Li do for all edge e in G.incidentEdges(v) do if edge e is unexplored then let w be the other endpoint of e if vertax w is unexplored then label e as a discovery edge insert w into Li+1 else label e as a cross edge i ? i+1 BFS 可以做什麼? 基本上,DFS 可以辦得到的事,BFS 也可以辦得到。 BFS 較適合用來尋找圖中的最短路徑 (其中距離是以邊的數目來計算的)。DFS 較適合解決複雜的連通性問題。 在實作上,BFS 使用到 Queue,而 DFS 則 使用到 Stack。 A B C D E F G H I J K L M
文档评论(0)