Articulation Points, Bridges, Bi-
connectivity“Critical nodes, critical edges” and connectivity
Ivaylo Kenov
Telerik Corporationhttp:/telerikacademy.
com
Telerik Academy Student
Table of Contents
1. Connectivity2. Articulation points3. Bridges4. Bi-connectivity
K-connectivity5. Algorithm6. Additional information
2
ConnectivityConnecting 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!
5
Connectivity (3)
6
foreach node from graph G{ if node is unvisited
{ DFS(node); counterOfComponents++;}
}
Algorithm:
*Note: Do not forget to mark each node in the DFS as visited!
Connectivity (4) Connected graph - 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!
7
Articulation pointWhat is it?
Articulation point (or node)
Usually used in unordered connected graphs (containing one connected component ).
If removed (with all its edges) divides the graph into 2 or more connected components.
Bridge"Articulation edge"
Bridge The same as articulation points but this time we remove edges.
If removed divides the graph into 2 or more connected components.
11
Bi-connectivityGraph with no articulation points
Bi-connectivity (1) An unordered connected 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.
13
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-connected graph is a graph in which if we remove any k-1 number of edges, it will remain connected.
14
AlgorithmFind articulation points
Algorithm (1) One easy (but not efficient) way to determine articulation point (and bi-connectivity) is to remove node by node from the graph and check whether it is still connected.
16
Algorithm (2) A node K is an articulation point if there are two other nodes I and J that each path between I and J goes through K.
This statement does not work for the root of the DFS traversal tree - it has no parent nodes.
17
Algorithm (3) So how to check the root? Easy! If it has two or more child elements - it is articulation point!
18
Algorithm (4) We use two arrays:
Prenumerator[] - we number the nodes in the graph with DFS instead 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
19
Algorithm (5)
20
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); } }
The altered DFS to numerate nodes:
Algorithm (6)
21
/* traversing the tree in postorder */ 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]); }
DFS tree traversal with post-order:
Algorithm (7)
22
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…
Articulation points algorithm:
Algorithm (8)
23
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[];}
Articulation points algorithm:
*Note: If you have a graph with huge number of nodes, you should use Stack instead of recursion in the algorithm!
AlgorithmLive 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;
25
форум програмиране, форум уеб дизайнкурсове и уроци по програмиране, уеб дизайн – безплатно
програмиране за деца – безплатни курсове и уроцибезплатен SEO курс - оптимизация за търсачки
уроци по уеб дизайн, HTML, CSS, JavaScript, Photoshop
уроци по програмиране и уеб дизайн за ученициASP.NET MVC курс – HTML, SQL, C#, .NET, ASP.NET MVC
безплатен курс "Разработка на софтуер в cloud среда"
BG Coder - онлайн състезателна система - online judge
курсове и уроци по програмиране, книги – безплатно от Наков
безплатен курс "Качествен програмен код"
алго академия – състезателно програмиране, състезанияASP.NET курс - уеб програмиране, бази данни, C#, .NET, ASP.NET
курсове и уроци по програмиране – Телерик академия
курс мобилни приложения с iPhone, Android, WP7, PhoneGapfree C# book, безплатна книга C#, книга Java, книга C# Дончо Минков - сайт за програмиране
Николай Костов - блог за програмиранеC# курс, програмиране, безплатно
?? ? ?
??? ?
?
? ?
??
?
?
? ?
Questions?
?http://algoacademy.telerik.com
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