Challenge - 5 Problems
Articulation Points Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of articulation points detection on a simple graph
What is the output of the following Java code that finds articulation points in a graph?
DSA Java
import java.util.*; public class Graph { private int V; private LinkedList<Integer>[] adj; private int time = 0; public Graph(int v) { V = v; adj = new LinkedList[v]; for (int i = 0; i < v; i++) { adj[i] = new LinkedList<>(); } } void addEdge(int v, int w) { adj[v].add(w); adj[w].add(v); } void APUtil(int u, boolean[] visited, int[] disc, int[] low, int[] parent, boolean[] ap) { int children = 0; visited[u] = true; disc[u] = low[u] = ++time; for (int v : adj[u]) { if (!visited[v]) { children++; parent[v] = u; APUtil(v, visited, disc, low, parent, ap); low[u] = Math.min(low[u], low[v]); if (parent[u] == -1 && children > 1) ap[u] = true; if (parent[u] != -1 && low[v] >= disc[u]) ap[u] = true; } else if (v != parent[u]) { low[u] = Math.min(low[u], disc[v]); } } } void findAP() { boolean[] visited = new boolean[V]; int[] disc = new int[V]; int[] low = new int[V]; int[] parent = new int[V]; boolean[] ap = new boolean[V]; for (int i = 0; i < V; i++) { parent[i] = -1; visited[i] = false; ap[i] = false; } for (int i = 0; i < V; i++) { if (!visited[i]) { APUtil(i, visited, disc, low, parent, ap); } } for (int i = 0; i < V; i++) { if (ap[i]) System.out.print(i + " "); } } public static void main(String[] args) { Graph g = new Graph(5); g.addEdge(1, 0); g.addEdge(0, 2); g.addEdge(2, 1); g.addEdge(0, 3); g.addEdge(3, 4); g.findAP(); } }
Attempts:
2 left
💡 Hint
Think about which vertices, if removed, increase the number of connected components.
✗ Incorrect
Vertices 0 and 3 are articulation points because removing them disconnects parts of the graph. Vertex 0 connects the triangle (0,1,2) with vertex 3 and 4. Vertex 3 connects vertex 4 to the rest.
🧠 Conceptual
intermediateUnderstanding articulation points in a graph
Which of the following statements about articulation points in an undirected graph is TRUE?
Attempts:
2 left
💡 Hint
Think about what happens to connectivity when a vertex is removed.
✗ Incorrect
An articulation point is defined as a vertex whose removal increases the number of connected components in the graph.
🔧 Debug
advancedIdentify the error in articulation points code snippet
What error will the following Java code produce when run?
DSA Java
int[] parent = new int[V]; boolean[] visited = new boolean[V]; int[] disc = new int[V]; int[] low = new int[V]; boolean[] ap = new boolean[V]; for (int i = 0; i < V; i++) { parent[i] = 0; visited[i] = false; ap[i] = false; } APUtil(0, visited, disc, low, parent, ap);
Attempts:
2 left
💡 Hint
Check the initialization of parent array and its effect on root detection.
✗ Incorrect
Parent array should be initialized to -1 to indicate no parent. Initializing to 0 causes incorrect root detection and may lead to wrong articulation point results.
🚀 Application
advancedNumber of articulation points in a complex graph
Given a graph with 7 vertices and edges: (0-1), (1-2), (2-0), (1-3), (1-4), (1-6), (3-5), (4-5), how many articulation points does it have?
Attempts:
2 left
💡 Hint
Identify vertices whose removal disconnects the graph.
✗ Incorrect
Vertices 1 and 3 are articulation points. Removing 1 disconnects vertices 3,4,5,6; removing 3 disconnects vertex 5.
❓ Predict Output
expertOutput of articulation points detection on a disconnected graph
What is the output of the following Java code that finds articulation points in a disconnected graph?
DSA Java
import java.util.*; public class Graph { private int V; private LinkedList<Integer>[] adj; private int time = 0; public Graph(int v) { V = v; adj = new LinkedList[v]; for (int i = 0; i < v; i++) { adj[i] = new LinkedList<>(); } } void addEdge(int v, int w) { adj[v].add(w); adj[w].add(v); } void APUtil(int u, boolean[] visited, int[] disc, int[] low, int[] parent, boolean[] ap) { int children = 0; visited[u] = true; disc[u] = low[u] = ++time; for (int v : adj[u]) { if (!visited[v]) { children++; parent[v] = u; APUtil(v, visited, disc, low, parent, ap); low[u] = Math.min(low[u], low[v]); if (parent[u] == -1 && children > 1) ap[u] = true; if (parent[u] != -1 && low[v] >= disc[u]) ap[u] = true; } else if (v != parent[u]) { low[u] = Math.min(low[u], disc[v]); } } } void findAP() { boolean[] visited = new boolean[V]; int[] disc = new int[V]; int[] low = new int[V]; int[] parent = new int[V]; boolean[] ap = new boolean[V]; for (int i = 0; i < V; i++) { parent[i] = -1; visited[i] = false; ap[i] = false; } for (int i = 0; i < V; i++) { if (!visited[i]) { APUtil(i, visited, disc, low, parent, ap); } } for (int i = 0; i < V; i++) { if (ap[i]) System.out.print(i + " "); } } public static void main(String[] args) { Graph g = new Graph(7); g.addEdge(0, 1); g.addEdge(1, 2); g.addEdge(2, 0); g.addEdge(1, 3); g.addEdge(1, 4); g.addEdge(1, 6); g.addEdge(3, 5); g.addEdge(4, 5); g.findAP(); } }
Attempts:
2 left
💡 Hint
Consider articulation points in each connected component separately.
✗ Incorrect
Vertices 1 and 3 are articulation points. Vertex 1 connects multiple parts, and vertex 3 connects vertex 5.
