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 C# code that finds articulation points in a graph?
DSA C#
using System; using System.Collections.Generic; class Graph { int V; List<int>[] adj; int time = 0; public Graph(int v) { V = v; adj = new List<int>[v]; for (int i = 0; i < v; i++) adj[i] = new List<int>(); } public void AddEdge(int u, int v) { adj[u].Add(v); adj[v].Add(u); } void APUtil(int u, bool[] visited, int[] disc, int[] low, int[] parent, bool[] ap) { visited[u] = true; disc[u] = low[u] = ++time; int children = 0; foreach (int v in 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]); } } } public void AP() { bool[] visited = new bool[V]; int[] disc = new int[V]; int[] low = new int[V]; int[] parent = new int[V]; bool[] ap = new bool[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]) Console.Write(i + " "); } } } class Program { static void Main() { 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.AP(); } }
Attempts:
2 left
💡 Hint
Think about which nodes, if removed, increase the number of connected components.
✗ Incorrect
The articulation points are nodes 0 and 3 because removing either disconnects the graph.
🧠 Conceptual
intermediateUnderstanding articulation points in a graph
Which of the following best describes an articulation point in a graph?
Attempts:
2 left
💡 Hint
Think about the effect of removing a vertex on the graph's connectivity.
✗ Incorrect
An articulation point is a vertex that, if removed, increases the number of connected components, breaking the graph into more pieces.
🔧 Debug
advancedIdentify the error in articulation points code snippet
What error will the following code produce when run?
DSA C#
int[] parent = new int[V]; for (int i = 0; i < V; i++) { parent[i] = 0; } // Later in DFS if (parent[u] == -1 && children > 1) ap[u] = true;
Attempts:
2 left
💡 Hint
Check how the root node is identified in the articulation point algorithm.
✗ Incorrect
The root node is identified by parent[u] == -1, but initializing parent array with 0 causes incorrect root detection.
❓ Predict Output
advancedOutput of articulation points in a disconnected graph
What is the output of the following code that finds articulation points in a disconnected graph?
DSA C#
using System; using System.Collections.Generic; class Graph { int V; List<int>[] adj; int time = 0; public Graph(int v) { V = v; adj = new List<int>[v]; for (int i = 0; i < v; i++) adj[i] = new List<int>(); } public void AddEdge(int u, int v) { adj[u].Add(v); adj[v].Add(u); } void APUtil(int u, bool[] visited, int[] disc, int[] low, int[] parent, bool[] ap) { visited[u] = true; disc[u] = low[u] = ++time; int children = 0; foreach (int v in 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]); } } } public void AP() { bool[] visited = new bool[V]; int[] disc = new int[V]; int[] low = new int[V]; int[] parent = new int[V]; bool[] ap = new bool[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]) Console.Write(i + " "); } } } class Program { static void Main() { Graph g = new Graph(7); g.AddEdge(0, 1); g.AddEdge(1, 2); g.AddEdge(2, 0); g.AddEdge(1, 3); g.AddEdge(3, 4); g.AddEdge(4, 5); g.AddEdge(5, 3); g.AddEdge(5, 6); g.AP(); } }
Attempts:
2 left
💡 Hint
Check articulation points in each connected component separately.
✗ Incorrect
Nodes 1, 3, and 5 are articulation points because their removal increases connected components.
🧠 Conceptual
expertArticulation points and bridges relationship
Which statement correctly describes the relationship between articulation points and bridges in a graph?
Attempts:
2 left
💡 Hint
Think about the difference between vertices and edges in graph connectivity.
✗ Incorrect
Bridges are edges that increase connected components when removed; articulation points are vertices with similar property. They are related but not the same.
