290 likes | 428 Views
Graph (III). Trees, Articulation point, Bridge, SCC. GGuy 19-3-2011. Review. Shortest path Dijkstra Bellman Ford Floyd Warshall Minimum Spanning Tree Prim’s Kruskal’s. Tree. The following four conditions are equivalent: G is connected and acyclic
E N D
Graph (III) Trees, Articulation point, Bridge, SCC GGuy 19-3-2011
Review Shortest path Dijkstra Bellman Ford Floyd Warshall Minimum Spanning Tree Prim’s Kruskal’s
Tree • The following four conditions are equivalent: • G is connected and acyclic • G is connected and |E| = |V| - 1 • G is acyclic and |E| = |V| - 1 • Between any pair of vertices in G, there exists a unique path • G is a tree if at least one of the above conditions is satisfied
Tree • |E| = |V| - 1 • Between any pair of vertices, there is a unique path • Adding an edge between a pair of non-adjacent vertices creates exactly one cycle • Removing an edge from the tree breaks the tree into two smaller trees
ancestors root parent siblings descendants children Tree
Tree Diameter Find the farthest node from root, say it u Find the farthest node from u, say it v (u, v) = Tree diameter
DFS Tree DFS (vertex u) { mark u as visited time = time + 1 birth[u] = time; for each vertex v directly reachable from u if v is unvisited parent[v] = u DFS (v) time = time + 1 death[u] = time; }
A D B E G E F C A D H F unvisited B visited visited (dead) C G H DFS forest (Demonstration) 1 2 3 13 10 4 14 6 12 9 8 16 11 5 15 7 - A B - A C D C
A D B E G C F H Classification of edges • Tree edge • Forward edge • Back edge • Cross edge • Question: which type of edges is always absent in an undirected graph?
Determination of edge types • How to determine the type of an arbitrary edge (u, v) after DFS? • Tree edge • parent [v] = u • Forward edge • not a tree edge; and • birth [v] > birth [u]; and • death [v] < death [u] • How about back edge and cross edge?
Articulation Point For a undirected graph G, Node u is an Articulation Point if remove u from G will create more components.
Bridge For a undirected graph G, Edge (u, v) is an bridge if remove (u, v) from G will create more components.
Finding AP and Bridge DFS(vertex u) time = time + 1 low[u] = vis[u] = time for each vertex v directly reachable from u if v is not visited DFS(v) low[u] = min(low[u], low[v]) if v is visited and parent of u is not v low[u] = min(low[u], vis[v])
Finding AP Find the DFS tree of G and compute low[] Vertex u is an AP if 1. u is the root and u has >1 children 2. u is not the root and there exists children v where low[v] >= vis[u]
Finding Bridge Find the DFS tree of G and compute low[] Edge (u, v) is a Bridge if 1. v is u children and low[v] > vis[u]
Bi-connected component A bi-connected component (or 2-connected component) is a maximal bi-connected subgraph A bi-connected subgraph is a graph that has no articulation point
Bi-connected component Each Bi-connected component is connected by bridge Each articulation point belongs to more than one Bi-connected component The Bi-connected components form a Tree
Strongly Connected Component In a directed graph G, a Strongly Connected Component is a subgraph that there is a path from each vertex to every other vertex in the same SCC.
Finding SCC • Compute the DFS forest of the graph G to get the death time of the vertices • Reverse all edges in G to form G’ • Compute a DFS forest of G’, but always choose the vertex with the latest death time when choosing the root for a new tree • The SCCs of G are the DFS trees in the DFS forest of G’
F A D B C G H SCC (Demonstration) 1 2 3 13 10 4 14 6 12 9 8 16 11 5 15 7 - A B - A C D C E F A E B H D A D G F B C C G H
A E B H E D F G F C A D B C G H SCC (Demonstration)
Finding SCC Assume (u, v) belongs to the same SCC WLOG, assume u is visited first. Since the exists a path from u to v, we have death[u] > death[v] When we do DFS on G’, we will call DFS(u) first. Since there exists a path from v to u in G, then there exists path from u to v in G’, hence v and u will be in the same tree.