9. Articulation Point - II
Problem Description
The problem can be found at the following link: Question Link
Given an undirected graph with V vertices and E edges, the graph is provided as a 2D array edges[][] where each element edges[i] = [u, v] indicates an undirected edge between vertices u and v. Your task is to return all the articulation points (or cut vertices) in the graph.
An articulation point is a vertex whose removal (along with all its connected edges) increases the number of connected components in the graph.
Note: The graph may be disconnected, i.e., it may consist of more than one connected component. If no such point exists, return
{-1}.
Note: Sorry for the delayed upload; my Final Semester exams are underway. Best of luck with your coding journey!
Example
Example 1:
Input:
V = 5
edges = [[0, 1], [1, 4], [4, 3], [4, 2], [2, 3]]Output:
[1, 4]Explanation:
Removing vertex 1 or 4 disconnects the graph. For instance, if vertex 1 is removed, the part of the graph connected to 1 becomes isolated from the rest of the components.
Example 2:
Input:
Output:
Explanation:
Removing vertex 0 will increase the number of disconnected components from 1 to 3.
Constraints
1 ≤ V, E ≤ 10⁴
My Approach
Optimized DFS Using Tarjan’s Algorithm
Algorithm Steps:
Convert the edge list to an adjacency list: Build an adjacency list from the given edges to represent the graph.
Use Tarjan’s DFS-based algorithm: During the DFS traversal, maintain two arrays:
disc[u]: The discovery time of vertex u.low[u]: The lowest discovery time reachable from u (including back-edges).
Identify Articulation Points:
For a non-root vertex u, if there is a child v such that
low[v] >= disc[u], then u is an articulation point.For the root vertex of the DFS, if it has more than one child, then it is an articulation point.
Handle Disconnected Graphs: Since the graph can be disconnected, run the DFS for every unvisited vertex.
Time and Auxiliary Space Complexity
Expected Time Complexity: O(V + E), as every vertex and edge is visited only once in the DFS traversal.
Expected Auxiliary Space Complexity: O(V + E), primarily for the recursion stack, the adjacency list, and the additional arrays used for tracking discovery times and low values.
Code (C++)
⚡ Alternative Approaches
📊 2️⃣ Biconnected Components (Using Modified Tarjan’s Algorithm)
This approach builds upon Tarjan’s algorithm by identifying biconnected components. The vertices that appear in more than one biconnected component are articulation points.
Algorithm Steps:
Perform DFS to compute discovery times (
disc[u]) and low values (low[u]).Maintain a stack of edges as part of the DFS to capture biconnected components.
For each vertex u, if a child v satisfies
low[v] >= disc[u], then u is an articulation point.Optionally, you can pop edges from the stack to report each biconnected component.
C++ Code:
📝 Complexity Analysis:
Time Complexity: O(V + E)
Space Complexity: O(V + E) (includes the recursion stack and the edge stack)
✅ Why Use This Approach?
Comprehensive Analysis: It not only finds articulation points but also helps in identifying biconnected components.
Applications: Particularly useful when the structure of biconnected components is needed, as in network reliability studies.
🆚 Comparison of Approaches
Approach
⏱️ Time Complexity
🗂️ Space Complexity
✅ Pros
⚠️ Cons
Tarjan’s Algorithm
🟢 O(V + E)
🟢 O(V + E)
Optimal, widely used, and efficient
Recursive (may hit limits for very deep graphs)
Biconnected Components (Modified Tarjan’s)
🟢 O(V + E)
🟡 O(V + E)
Provides extra insight into the structure of the graph
Slightly more complex to implement
✅ Best Choice?
For efficient and optimal detection of articulation points, Tarjan’s algorithm is the best choice.
The biconnected components approach is useful when additional component structure is required.
Code (Java)
Code (Python)
Contribution and Support:
For discussions, questions, or doubts related to this solution, feel free to connect on LinkedIn: Any Questions. Let’s make this learning journey more collaborative!
⭐ If you find this helpful, please give this repository a star! ⭐
📍Visitor Count
Last updated