Articulation Points in Graph in DSA C# - Time & Space Complexity
We want to understand how the time needed to find articulation points changes as the graph grows.
How does the algorithm's work increase when the graph has more nodes and edges?
Analyze the time complexity of the following code snippet.
void DFS(int u, int parent) {
visited[u] = true;
disc[u] = low[u] = ++time;
int children = 0;
foreach (int v in graph[u]) {
if (!visited[v]) {
children++;
DFS(v, u);
low[u] = Math.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] = Math.Min(low[u], disc[v]);
}
}
}
This code finds articulation points using DFS traversal and tracks discovery and low times.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: DFS visits each node once and checks all its neighbors.
- How many times: Each edge is checked at most twice during the DFS traversal.
As the graph grows, the algorithm visits every node and edge once or twice.
| Input Size (n nodes, m edges) | Approx. Operations |
|---|---|
| 10 nodes, 15 edges | About 40 operations |
| 100 nodes, 200 edges | About 600 operations |
| 1000 nodes, 5000 edges | About 12000 operations |
Pattern observation: Operations grow roughly in proportion to nodes plus edges.
Time Complexity: O(n + m)
This means the time grows linearly with the number of nodes and edges in the graph.
[X] Wrong: "The algorithm checks every possible path, so it must be exponential."
[OK] Correct: The DFS visits each node and edge only once or twice, so it does not explore all paths separately.
Understanding this time complexity helps you explain how graph traversal algorithms scale and why DFS-based solutions are efficient for connectivity problems.
"What if the graph is represented as an adjacency matrix instead of adjacency lists? How would the time complexity change?"
Practice
Solution
Step 1: Understand the definition of articulation point
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 DQuick Check:
Articulation point = vertex increasing components when removed [OK]
- Confusing articulation point with highest degree vertex
- Thinking articulation point is a vertex with no edges
- Mixing articulation point with cycle formation
Solution
Step 1: Identify common graph representation in C#
Adjacency list is often represented as List<int>[] for vertices count known.Step 2: Check method signature compatibility
public void FindArticulationPoints(List<int>[] graph, int vertices) uses List<int>[] and vertices count, suitable for articulation point algorithm.Final Answer:
public void FindArticulationPoints(List<int>[] graph, int vertices) -> Option AQuick Check:
Adjacency list with vertex count = correct signature [OK]
- Using 2D array instead of adjacency list
- Returning int or bool instead of void
- Using Dictionary without vertex count parameter
0 - 1, 1 - 2, 2 - 0, 1 - 3Which vertex is an articulation point?
Solution
Step 1: Visualize the graph connections
Vertices 0,1,2 form a triangle (cycle). Vertex 3 connects only to 1.Step 2: Identify articulation points
Removing vertex 1 disconnects vertex 3 from the rest, increasing components. Others do not disconnect graph.Final Answer:
Vertex 1 -> Option CQuick Check:
Removing vertex 1 splits graph = articulation point [OK]
- Assuming all vertices in cycle are articulation points
- Ignoring leaf vertex connections
- Confusing vertex numbers
void DFS(int u, int parent) {
visited[u] = true;
disc[u] = low[u] = time++;
int children = 0;
foreach(var v in graph[u]) {
if (!visited[v]) {
children++;
DFS(v, u);
low[u] = Math.Min(low[u], low[v]);
if (parent != -1 && low[v] >= disc[u])
articulation[u] = true;
} else if (v != parent) {
low[u] = Math.Min(low[u], disc[v]);
}
}
if (parent == -1 && children > 1)
articulation[u] = true;
}What is the bug in this code?
Solution
Step 1: Analyze usage of 'time' variable
'time' is used to assign discovery times but code snippet does not show initialization or global declaration.Step 2: Check other conditions
Conditions and logic for articulation points are correct; 'time' must be properly initialized and incremented outside DFS.Final Answer:
The variable 'time' is not initialized or incremented properly -> Option BQuick Check:
Uninitialized 'time' breaks discovery time tracking [OK]
- Changing correct condition to strict inequality
- Removing parent check causing wrong low updates
- Resetting articulation inside DFS causing wrong results
0-1, 1-2, 2-0, 1-3, 3-4Which vertices are articulation points?
Solution
Step 1: Visualize the graph structure
Vertices 0,1,2 form a triangle. Vertex 3 connects to 1 and 4. Vertex 4 is leaf.Step 2: Identify articulation points
Removing 1 disconnects 3 and 4. Removing 3 disconnects 4. Vertices 0,2 are in cycle, not articulation points. Vertex 4 is leaf, not articulation.Final Answer:
[1, 3] -> Option AQuick Check:
Vertices disconnecting graph when removed = [1, 3] [OK]
- Including leaf vertex as articulation point
- Confusing cycle vertices as articulation points
- Missing vertex 3 as articulation point
Ready to prove it?
Pass the test and this pattern moves unknown
