πDay 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 Walkthrough:
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.
π Solution Code
Code (C++)
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