收藏 分享(赏)

算法设计与分析14UndirectG.ppt

上传人:lxhqcj 文档编号:7281979 上传时间:2019-05-12 格式:PPT 页数:22 大小:201KB
下载 相关 举报
算法设计与分析14UndirectG.ppt_第1页
第1页 / 共22页
算法设计与分析14UndirectG.ppt_第2页
第2页 / 共22页
算法设计与分析14UndirectG.ppt_第3页
第3页 / 共22页
算法设计与分析14UndirectG.ppt_第4页
第4页 / 共22页
算法设计与分析14UndirectG.ppt_第5页
第5页 / 共22页
点击查看更多>>
资源描述

1、DFS Search on Undirected Graphs,Algorithm : Design & Analysis 14,In the last class,Directed Acyclic Graph Topological Order Critical Path Analysis Strongly Connected Component Strong Component and Condensation Leader of Strong Component The Algorihtm,DFS Search on Undirected Graph,Undirected and Sym

2、metric Digraph UDF Search Skeleton Biconnected Components Articulation Points and Biconnectedness Biconnected Component Algorithm Analysis of the Algorithm,Orientation of edges by DFS,The issue related to traversals for undirected graph is that one edge may be traversed for two times in opposite dir

3、ections. For an undirected graph, the depth-first search provides an orientation for each of its edges; they are oriented in the direction in which they are first encountered.,Nontree edges in symmetric digraph,Cross edge: not existing. Back edge: Back to the direct parent: second encounter Otherwis

4、e: first encounter Forward edge:always second encounter,Modifications to the DFS Skeleton,All the second encounter are bypassed. So, the only substantial modification is for the possible back edges leading to an ancestor, but not direct parent.,DFS Skeleton for Undirected Graph,int dfsSweep(IntList

5、adjVertices,int n, )int ans;For each vertex v of G, in some orderif (colorv=white)int vAns=dfs(adjVertices, color, v, -1, );/ Continue loopreturn ans;,Recording the direct parent,DFS Skeleton for Undirected Graph,int dfs(IntList adjVertices, int color, int v, int p, )int w; IntList remAdj; int ans;c

6、olorv=gray;remAdj=adjVerticesv;while (remAdjnil)w=first(remAdj);if (colorw=white)int wAns=dfs(adjVertices, color, w, v );else if (colorw=gray ,In all other cases, the edges are the second encounter, so, ignored.,Complexity of Undirected DFS,If each inserted statement for specialized application runs

7、 in constant time, the time cost is the same as for directed DFS, that is (m+n). Extra space is in (n) for array color, or activation frames of recursion.,Definition of Biconnected Components,Biconnected component Biconnected graph Bicomponent: a maximal biconnected subgraph Articulation point v is

8、an articulation point if it is in every path from w to x (w,x are vertices different from v) A connected graph is biconnected if and only if it has no articulation points.,B,Bicomponents,F,E,F,B,E,Partitioning the set of edges, not of the vertices,Bicomponent Algorithm: the Idea,v,w,Ancestors of v,S

9、ubtree rooted at w,Back edge,v is an articulation point if and only if no back edges linking any vertex in v-rooted subtree and any ancestor of v.,If v is the articulation point farthest away from the root on the branch, then one bicomponent is detected.,Keeping the Track of Backing,Tracking data Fo

10、r each vertex v, a local variable back is used to store the required information, as the value of discoverTime of some vertex. Testing for bicomponent At backtracking from w to v, the condition implying a bicomponent is: wBack discoverTime(v) (where wBack is the returned back value for w),Updating t

11、he value of back,v first discovered back=discoverTime(v) Trying to explore, but a back edge vw from v encountered back=min(back, discoverTime(w) Backtracking from w to v back=min(back, wback),Bicomponent: an Example,1/1,2/2,3/3,first back edge encountered,1/1,3/1,4/4,6/6,5/5,second back edge encount

12、ered,2/2,Bicomponent: an Example,1/1,3/1,4/4,5/4,6/4,backtracking,2/2,1/1,3/1,4/4,5/4,6/4,2/2,8/8,9/9,third back edge encountered,Bicomponent: an Example,1/1,3/1,4/4,5/4,2/2,8/5,9/5,6/4,backtracking,1/1,3/1,4/4,5/4,2/2,8/5,9/5,6/4,backtracking: gBack=discoverTime(B), so, first bicomponent detected.,

13、Bicomponent: an Example,1/1,3/1,4/4,5/4,2/2,8/5,9/5,6/4,Backtracking from B to E: bBack=discoverTime(E), so, the second bicomponent is detect,Backtracking from E to F: eBackdiscoverTime(F), so, the third bicomponent is detect,14/1,16/2,int bicompDFS(v)colorv=gray; time+; discoverTimev=time;back=disc

14、overTimev;while (there is an untraversed edge vw)if (vw is a tree edge)wBack=bicompDFS(w);if (wBackdiscoverTimev)Output a new bicomponent by popping edgeStack down through vw ;back=min(back, wBack);else if (vw is a back edge)back=min(discoverTimev, back);time+; finishTimev=time; colorv=black; return

15、 back;,Bicomponent Algorithm: Core,Outline of core procedure,Correctness of Bicomponent Algorithm,In a DFS tree, a vertex(not root) v is an articulation point if and only if (1)v is not a leaf; (2) some subtree of v has no back edge incident with a proper ancestor of v. By definition, v is on every

16、path between some x,y(different from v). At least one of x,y is a proper descendent of v(otherwise, xrooty not containing v). By contradiction, suppose that every subtree of v has a back edge to a proper ancestor of v, we can find a xy-path not containing v for all possible cases(only 2 cases),Cases Leading to Contradiction,x,y,v,x,v,y,Case 1: one descendant,x,y,v,Case 2: both descendants,Home Assignments,pp.380- 7.28 7.35 7.37 7.38 7.40,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 网络科技 > 数据结构与算法

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


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

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

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