320 likes | 543 Views
Articulation Points, Bridges, Bi-connectivity. “Critical nodes, critical edges” and connectivity. Ivaylo Kenov. Telerik Corporation. http:/telerikacademy.com. Telerik Academy Student. Table of Contents. Connectivity Articulation points Bridges Bi-connectivity K-connectivity
E N D
Articulation Points, Bridges, Bi-connectivity “Critical nodes, critical edges” and connectivity IvayloKenov Telerik Corporation http:/telerikacademy.com Telerik Academy Student
Table of Contents • Connectivity • Articulation points • Bridges • Bi-connectivity • K-connectivity • Algorithm • Additional information
Connectivity Connecting the chain
Connectivity (1) • Connected component of undirected graph – a subgraph in which any two nodes are connected to each other by paths.
Connectivity (2) • A simple way to find number of connected components - loop through all nodes and start a DFS or BFS traversing from any unvisited node. • Each time you start a new traversing - you find a new connected component!
Connectivity (3) • Algorithm: foreach node from graph G { if node is unvisited { DFS(node); counterOfComponents++; } } *Note: Do not forget to mark each node in the DFS as visited!
Connectivity (4) • Connectedgraph- basically a graph with one connected component • In every connected graph a path exists between any two nodes • Easy algorithm for checking whether a graph is connected - if the previous code return one connected component - graph is connected!
Articulation point What is it?
Articulation point (or node) Usually used in unorderedconnectedgraphs(containing one connected component ). If removed (with all its edges) divides the graph into 2ormoreconnected components.
Bridge "Articulation edge"
Bridge • The same as articulation points but this time we remove edges. • If removed divides the graph into 2ormoreconnected components.
Bi-connectivity Graph with no articulation points
Bi-connectivity (1) • An unorderedconnected graph is called bi-connected when if we remove 1 of its nodes (no matter which one), the graph will remain connected (with 1 connected component). • Has no articulation points.
Bi-connectivity (2) • k-vertex-connected graph is a graph in which if we remove any k-1 number of nodes, it will remain connected.w • k-edge-connectedgraph is a graph in which if we remove any k-1 number of edges, it will remain connected.
Algorithm Find articulation points
Algorithm (1) • One easy (butnotefficient) way to determine articulation point (and bi-connectivity) is to remove node by node from the graph and check whether it is still connected.
Algorithm (2) • A node Kis an articulation point if there are two other nodes Iand Jthat each path between Iand Jgoes through K. • This statement doesnotworkfor the root of the DFS traversal tree - it has no parent nodes.
Algorithm (3) • So how to check the root? • Easy! If it has twoormorechild elements - it is articulation point!
Algorithm (4) • We use two arrays: • Prenumerator[] - we number the nodes in the graph with DFSinstead of just mark them as visited • Lowest[] - the least numbered node that can be obtained by a back edge to one of its ancestors or the least node that can be obtained by a back edge from any one of its descendants. • The check - if the DFS number of the node is <= to the Lowest of any of its children
Algorithm (5) • The altered DFS to numerate nodes: function DFS(i) { prenumerator[i] = ++DFScounter; for (j = 0; j < numberOfNodes; j++) if (A[i][j] != 0 && prenum[j] == 0) { A[i][j] = 2; /* building DFS tree of the graph*/ DFS(j); } }
Algorithm (6) • DFS tree traversal with post-order: /* traversing the tree inpostorder */ function postOrder(i) { unsigned j; for (j = 0; j < numberOfNodes; j++) if (2 == A[i][j]) postOrder(j); lowest[i] = prenumerator[i]; for (j = 0; j < numberOfNodes; j++) if (1 == A[i][j]) lowest[i] = min(lowest[i], prenumerator[j]); for (j = 0; j < numberOfNodes; j++) if (2 == A[i][j]) lowest[i] = min(lowest[i], lowest[j]); }
Algorithm (7) • Articulation points algorithm: function findArticPoints() { articulationPoints[], count; for (i = 0; i < numberOfNodes; i++) { prenum[i] = 0; lowest[i] = 0; artPoints[i] = 0; } DFScounter= 0; DFS(0); for (i = 0; i < numberOfNodes; i++) if (0 == prenumerator[i]) { “Graph is not connected!"; return; } postOrder(0); count = 0; for (i = 0; i < numberOfNodes; i++) //checking root if (2 == A[0][i]) count++; if (count > 1) artPoints[0] = 1; Continues…
Algorithm (8) • Articulation points algorithm: Continues… /* checking the rest of the nodes*/ for (i = 1; i < numberOfNodes; i++) { for (j = 0; j < numberOfNodes; j++) if (2 == A[i][j] && lowest[j] >= prenum[i]) break; if (j < n) artPoints[i] = 1; } Print the result from arcPoints[]; } *Note: If you have a graph with huge number of nodes, you should use Stackinstead of recursion in the algorithm!
Algorithm Live demo
Additional information • Bi-connectivity: http://www.seas.gwu.edu/~ayoussef/cs212/graphsearch.html#biconnectivity • Algorithm for articulation points: http://nbangla.blogspot.com/2012/12/cpp-articulation-points-detection-algorithm.html • Algorithm for bridges: http://www.aspfree.com/c/a/code-examples/articulation-edges-and-vertexes/ • “Programming = ++Algorithms” by P. Nakov;
Free Trainings @ Telerik Academy • “C# Programming @ Telerik Academy • csharpfundamentals.telerik.com • Telerik Software Academy • academy.telerik.com • Telerik Academy @ Facebook • facebook.com/TelerikAcademy • Telerik Software Academy Forums • forums.academy.telerik.com