📖 Scenario: You are working as a network engineer. You want to find critical computers (nodes) in a network that, if removed, would break the network into disconnected parts. These critical nodes are called articulation points.We will represent the network as a graph using adjacency lists.
🎯 Goal: Build a program in C to find all articulation points in an undirected graph using DFS and low-link values.
📋 What You'll Learn
Create an adjacency list representation of the graph with 5 nodes and given edges
Add arrays to track discovery times, low values, and articulation points
Implement DFS to find articulation points using Tarjan's algorithm
Print all articulation points found in the graph
💡 Why This Matters
🌍 Real World
Finding articulation points helps identify critical nodes in computer networks, social networks, or transportation systems that can cause disconnection if removed.
💼 Career
Network engineers, system architects, and software developers use articulation point detection to improve network reliability and fault tolerance.
Progress0 / 4 steps
1
Create the graph adjacency list
Create an integer V with value 5 for number of vertices. Create an adjacency list array called adj of size V where each element is a pointer to an integer array. Initialize the adjacency list with these edges: 0-1, 0-2, 1-2, 1-3, 3-4.
DSA C
Hint
Use an array of pointers for adjacency list. Use a helper function add_edge to add edges both ways.
2
Add arrays for DFS tracking
Add integer arrays disc, low, and parent of size V. Also add a boolean array ap of size V to mark articulation points. Initialize all disc and low values to -1, all parent values to -1, and all ap values to 0.
DSA C
Hint
Use arrays of size V to track discovery time, low values, parents, and articulation points. Initialize them properly.
3
Implement DFS to find articulation points
Write a recursive function APUtil with parameters int u, int* time. Inside, set disc[u] and low[u] to ++(*time). Use a variable children to count DFS tree children. For each adjacent vertex v of u, if disc[v] is -1, set parent[v] = u, recursively call APUtil(v, time), update low[u] with minimum of low[u] and low[v]. Mark ap[u] = 1 if u is root with more than one child or if low[v] >= disc[u] for non-root. If disc[v] is not -1 and v != parent[u], update low[u] with minimum of low[u] and disc[v]. Call APUtil for all vertices with disc[i] == -1 in main.
DSA C
Hint
Use DFS recursion with discovery and low times. Update articulation points based on conditions for root and non-root nodes.
4
Print all articulation points
Add a for loop in main to print all vertices i where ap[i] == 1. Print them in the format: "Articulation Point: i\n".
DSA C
Hint
Loop through ap array and print all indices where value is 1.
Practice
(1/5)
1. What is an articulation point in a graph?
easy
A. A vertex that has no edges connected to it
B. A vertex with the highest degree in the graph
C. A vertex that, when removed, increases the number of connected components
D. A vertex connected to all other vertices
Solution
Step 1: Understand articulation point definition
An articulation point is a vertex that, if removed, breaks the graph into more pieces (connected components).
Step 2: Compare options with definition
Only 'A vertex that, when removed, increases the number of connected components' matches this definition exactly.
Final Answer:
A vertex that, when removed, increases the number of connected components -> Option C
Quick Check:
Articulation point = vertex increasing components when removed [OK]
Hint: Articulation point splits graph if removed [OK]
Common Mistakes:
Confusing articulation point with highest degree vertex
Thinking articulation point is always connected to all vertices
Assuming isolated vertices are articulation points
2. Which of the following is the correct way to declare a graph adjacency list in C++ for articulation point detection?
easy
A. int graph[100][100];
B. vector<int> graph[100];
C. int* graph = malloc(sizeof(int) * 100);
D. int graph[100];
Solution
Step 1: Understand adjacency list representation
An adjacency list stores neighbors for each vertex, best done with an array of vectors in C++ or array of lists in C.
Step 2: Analyze options
vector<int> graph[100];: vector<int> graph[100]; is correct for adjacency list in C++ (common in DSA). int graph[100][100]; is 2D array (adjacency matrix). int* graph = malloc(sizeof(int) * 100); is incorrect memory allocation. int graph[100]; is single array, insufficient for lists.
Final Answer:
vector<int> graph[100]; -> Option B
Quick Check:
Adjacency list = array of vectors [OK]
Hint: Use array of vectors for adjacency list in C++ [OK]
Common Mistakes:
Using 2D arrays for adjacency list instead of adjacency matrix
Incorrect memory allocation for adjacency list
Confusing adjacency list with adjacency matrix
3. Consider the following code snippet for articulation point detection in a graph with 4 vertices (0 to 3):
void dfs(int u, int parent) {
visited[u] = true;
disc[u] = low[u] = ++time;
int children = 0;
for (int v : graph[u]) {
if (!visited[v]) {
children++;
dfs(v, u);
low[u] = min(low[u], low[v]);
if (parent == -1 && children > 1)
articulation[u] = true;
if (parent != -1 && low[v] >= disc[u])
articulation[u] = true;
} else if (v != parent) {
low[u] = min(low[u], disc[v]);
}
}
}
What will be the value of articulation[1] after running dfs(0, -1) on the graph edges: 0-1, 1-2, 1-3?
medium
A. true
B. false
C. undefined
D. depends on order
Solution
Step 1: Analyze graph structure and DFS
Graph edges: 0-1, 1-2, 1-3. Vertex 1 connects 0 to 2 and 3. Removing 1 disconnects graph.
Step 2: Apply articulation point logic
Since 1 is not root (parent != -1) and low[v] >= disc[u] condition holds for children 2 and 3, articulation[1] is set true.