Articulation Points (or Cut Vertices) in a Graph
Given a graph, the task is to find the articulation points in the given graph.
Note: A vertex in an undirected connected graph is an articulation point (or cut vertex) if removing it (and edges through it) disconnects the graph. Articulation points represent vulnerabilities in a connected network – single points whose failure would split the network into 2 or more components. They are useful for designing reliable networks. For a disconnected undirected graph, an articulation point is a vertex removal which increases the number of connected components.
Output: 0, 3
Output: 1, 2
Below is the idea to solve the problem:
A simple approach is to one by one remove all vertices and see if removal of a vertex causes disconnected graph.
Following the below steps to Implement the idea:
- Iterate over all the vertices and for every vertex do the following:
- Remove v from graph
- See if the graph remains connected (We can either use BFS or DFS)
- Add v back to the graph
Time Complexity: O(V*(V+E)) for a graph represented using an adjacency list.
Auxiliary Space: O(V+E)
Articulation Points (or Cut Vertices) in a Graph using Tarjan’s Algorithm:
The idea is to use DFS (Depth First Search). In DFS, follow vertices in a tree form called the DFS tree. In the DFS tree, a vertex u is the parent of another vertex v, if v is discovered by u.
In DFS tree, a vertex u is an articulation point if one of the following two conditions is true.
- u is the root of the DFS tree and it has at least two children.
- u is not the root of the DFS tree and it has a child v such that no vertex in the subtree rooted with v has a back edge to one of the ancestors in DFS tree of u.
The following figure shows the same points as above with one additional point that a leaf in DFS Tree can never be an articulation point.
Follow the below steps to Implement the idea:
- Do DFS traversal of the given graph
- In DFS traversal, maintain a parent array where parent[u] stores the parent of vertex u.
- To check if u is the root of the DFS tree and it has at least two children. For every vertex, count children. If the currently visited vertex u is root (parent[u] is NULL) and has more than two children, print it.
- To handle a second case where u is not the root of the DFS tree and it has a child v such that no vertex in the subtree rooted with v has a back edge to one of the ancestors in DFS tree of u maintain an array disc to store the discovery time of vertices.
- For every node u, find out the earliest visited vertex (the vertex with minimum discovery time) that can be reached from the subtree rooted with u. So we maintain an additional array low such that:
low[u] = min(disc[u], disc[w]) , Here w is an ancestor of u and there is a back edge from some descendant of u to w.
Below is the Implementation of the above approach:
Articulation points in first graph 0 3 Articulation points in second graph 1 2 Articulation points in third graph 1
Time Complexity: O(V+E), For DFS it takes O(V+E) time.
Auxiliary Space: O(V+E), For visited array, adjacency list array.
Please Login to comment...