📖 Scenario: You are working as a network engineer. You want to find critical computers in a network. If these computers fail, the network breaks into disconnected parts. These critical computers are called articulation points.The network is shown as a graph where computers are nodes and connections are edges.
🎯 Goal: Build a program to find all articulation points in a given graph using depth-first search.
📋 What You'll Learn
Create a graph as an adjacency list with exact nodes and edges
Create variables to track discovery times and low values
Implement DFS to find articulation points using Tarjan's algorithm
Print the list of articulation points found
💡 Why This Matters
🌍 Real World
Network engineers use articulation points to find critical devices whose failure can break communication.
💼 Career
Understanding articulation points helps in network design, reliability analysis, and troubleshooting.
Progress0 / 4 steps
1
Create the graph as an adjacency list
Create a variable called graph as an object representing the graph with these exact connections: 0: [1, 2], 1: [0, 2], 2: [0, 1, 3, 5], 3: [2, 4], 4: [3], 5: [2, 6, 8], 6: [5, 7], 7: [6, 8], 8: [5, 7]
DSA Javascript
Hint
Use an object where keys are node numbers and values are arrays of connected nodes.
2
Create helper variables for DFS
Create variables time set to 0, disc as an empty object, low as an empty object, parent as an empty object, and articulationPoints as an empty Set.
DSA Javascript
Hint
Use let for time and const for the objects and Set.
3
Implement DFS function to find articulation points
Write a function called dfs that takes a node u. Inside, set disc[u] and low[u] to ++time. Initialize children to 0. For each neighbor v of u in graph[u], if disc[v] is undefined, set parent[v] = u, increment children, call dfs(v), update low[u] to Math.min(low[u], low[v]). If parent[u] is undefined and children > 1, add u to articulationPoints. If parent[u] is defined and low[v] >= disc[u], add u to articulationPoints. Else if v !== parent[u], update low[u] to Math.min(low[u], disc[v]). Then, run dfs(u) for each node u in graph if disc[u] is undefined.
DSA Javascript
Hint
Follow Tarjan's algorithm steps carefully. Use recursion and update low and disc arrays.
4
Print the articulation points
Write a console.log statement to print the array of articulation points by converting articulationPoints Set to an array.
DSA Javascript
Hint
Use console.log(Array.from(articulationPoints)) to print the articulation points as an array.
Practice
(1/5)
1. What is an articulation point in a graph?
easy
A. A vertex that, when removed, increases the number of connected components
B. A vertex with the highest degree in the graph
C. A vertex connected to all other vertices
D. A vertex that has no edges connected to it
Solution
Step 1: Understand the definition of articulation point
An articulation point is a vertex that, if removed, increases the number of disconnected parts in the graph.
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 A
Quick Check:
Articulation point = vertex increasing components when removed [OK]
Hint: Articulation point breaks graph connectivity when 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 initialize a graph adjacency list in JavaScript for articulation point detection?
easy
A. const graph = Array.from({ length: n }, () => []);
B. const graph = new Array(n).fill([]);
C. const graph = Array(n).fill(null);
D. const graph = new Map();
Solution
Step 1: Understand adjacency list initialization
We need an array of separate empty arrays for each vertex to store neighbors.
Step 2: Analyze options
const graph = new Array(n).fill([]); uses fill([]), which fills all positions with the same array reference (wrong). const graph = Array.from({ length: n }, () => []); uses Array.from with a function returning new arrays, so each vertex has its own array (correct). const graph = Array(n).fill(null); fills with null, not arrays. const graph = new Map(); uses Map, which is valid but not the typical adjacency list array.
Final Answer:
const graph = Array.from({ length: n }, () => []); -> Option A
Quick Check:
Separate arrays per vertex = const graph = Array.from({ length: n }, () => []); [OK]
Hint: Use Array.from with function to create separate arrays [OK]
Common Mistakes:
Using fill([]) creates shared references causing bugs
Initializing with null instead of arrays
Confusing Map with adjacency list array
3. Consider the following JavaScript code snippet for finding articulation points in a graph with 4 vertices (0 to 3):
const graph = [[1,2],[0],[0,3],[2]];
const visited = [false, false, false, false];
const disc = [0, 0, 0, 0];
const low = [0, 0, 0, 0];
const parent = [-1, -1, -1, -1];
const ap = [false, false, false, false];
let time = 0;
function dfs(u) {
visited[u] = true;
disc[u] = low[u] = ++time;
let children = 0;
for (const v of graph[u]) {
if (!visited[v]) {
children++;
parent[v] = u;
dfs(v);
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]);
}
}
}
dfs(0);
console.log(ap);
What will be the output printed?
medium
A. [false, false, false, false]
B. [true, false, true, false]
C. [true, true, false, false]
D. [false, true, true, false]
Solution
Step 1: Trace DFS and articulation point logic
Start DFS at 0: children are 1 and 2. For root (0), if children > 1, ap[0] = true. So 0 is articulation point. For vertex 2, low[3] >= disc[2] triggers ap[2] = true.
Step 2: Determine articulation points array
Vertices 0 and 2 are articulation points, others are not. So ap = [true, false, true, false].
Final Answer:
[true, false, true, false] -> Option B
Quick Check:
Root with >1 child and low[v]>=disc[u] mark articulation points [OK]
Hint: Root with multiple children and low[v]>=disc[u] mark articulation points [OK]
Common Mistakes:
Ignoring root special case with multiple children
Confusing low and disc arrays
Not updating low[u] on back edges
4. The following code attempts to find articulation points but has a bug:
function dfs(u) {
visited[u] = true;
disc[u] = low[u] = ++time;
let children = 0;
for (const v of graph[u]) {
if (!visited[v]) {
children++;
parent[v] = u;
dfs(v);
low[u] = Math.min(low[u], low[v]);
if (low[v] >= disc[u]) ap[u] = true;
} else if (v !== parent[u]) {
low[u] = Math.min(low[u], disc[v]);
}
}
}
What is the bug in this code?
medium
A. It does not mark visited vertices
B. It uses '>' instead of '>=' in the articulation point check
C. It does not update parent array correctly
D. It misses the root vertex articulation point condition
Solution
Step 1: Analyze articulation point conditions
The code checks if low[v] >= disc[u] to mark articulation points but misses the special case for root vertex which requires children > 1.
Step 2: Identify missing root condition
Without checking if u is root and has multiple children, root articulation points won't be detected.
Final Answer:
It misses the root vertex articulation point condition -> Option D
Quick Check:
Root articulation point requires separate children > 1 check [OK]
Hint: Always check root vertex children count separately [OK]
Common Mistakes:
Forgetting root vertex special case
Using wrong comparison operator in articulation check
Not updating parent array before DFS call
5. Given a connected undirected graph with 5 vertices and edges: 0-1, 1-2, 2-0, 1-3, 3-4, which vertices are articulation points?
hard
A. [1]
B. [0, 1, 3]
C. [1, 3]
D. [3, 4]
Solution
Step 1: Visualize the graph and connections
Vertices 0,1,2 form a triangle. Vertex 1 connects to 3, which connects to 4.
Step 2: Identify articulation points
Removing 1 disconnects 3 and 4 from the rest, so 1 is articulation point. Removing 3 disconnects 4, so 3 is articulation point. 0,2,4 are not articulation points.
Final Answer:
[1, 3] -> Option C
Quick Check:
Vertices connecting subgraphs are articulation points [OK]
Hint: Articulation points connect separate graph parts [OK]
Common Mistakes:
Including vertices inside cycles as articulation points
Missing leaf node articulation points
Confusing articulation points with bridges
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.