📖 Scenario: Imagine a city's road network represented as a graph. Each intersection is a node, and each road is an edge connecting two intersections. Some intersections are critical: if they close, parts of the city become unreachable. These are called articulation points.
🎯 Goal: You will build a Rust program to find all articulation points in a given undirected graph. This helps identify critical intersections in the city road network.
📋 What You'll Learn
Create a graph using adjacency lists with exact nodes and edges
Create variables to track discovery times and low values for each node
Implement a depth-first search (DFS) to find articulation points using Tarjan's algorithm
Print the list of articulation points found in the graph
💡 Why This Matters
🌍 Real World
Finding articulation points helps city planners identify critical intersections that need reinforcement or alternative routes to avoid traffic jams or isolation.
💼 Career
Understanding graph algorithms like articulation points is essential for roles in network design, infrastructure planning, cybersecurity, and software engineering involving complex data relationships.
Progress0 / 4 steps
1
Create the graph adjacency list
Create a variable called graph as a Vec> with 5 nodes (0 to 4) and these edges: 0-1, 0-2, 1-2, 1-3, 3-4.
DSA Rust
Hint
Use a vector of vectors to represent the graph. Add edges in both directions because the graph is undirected.
2
Create tracking variables for DFS
Add these variables after the graph: let mut time = 0;, let mut disc = vec![-1; 5];, let mut low = vec![-1; 5];, and let mut articulation_points = vec![false; 5];.
DSA Rust
Hint
Use vectors of length 5 initialized with -1 for discovery and low times, and false for articulation points.
3
Implement DFS function to find articulation points
Define a function dfs with parameters u: usize, parent: Option, graph: &Vec>, time: &mut i32, disc: &mut Vec, low: &mut Vec, and articulation_points: &mut Vec. Implement Tarjan's algorithm inside it to update disc, low, and articulation_points. Then call dfs(0, None, &graph, &mut time, &mut disc, &mut low, &mut articulation_points); inside main.
DSA Rust
Hint
Use recursion to visit nodes. Update discovery and low times. Mark articulation points based on Tarjan's rules.
4
Print the articulation points
Add a for loop in main to print all node indices where articulation_points[node] is true. Print each node on its own line.
DSA Rust
Hint
Loop through all nodes and print those marked as articulation points.
Practice
(1/5)
1. What is an articulation point in a graph?
easy
A. A vertex with the highest degree in the graph
B. A vertex that, when removed, increases the number of connected components
C. A vertex that has no edges connected to it
D. A vertex that forms a cycle with its neighbors
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 B
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 a vertex with no edges
Mixing articulation point with cycle forming vertex
2. Which Rust data structure is best suited to store the graph for finding articulation points?
easy
A. Vec (adjacency list)
B. HashMap
C. Vec<usize> (simple list)
D. String
Solution
Step 1: Identify graph representation for articulation points
Graphs are commonly stored as adjacency lists for efficient traversal and edge lookup.
Step 2: Match Rust data structures
Vec represents adjacency lists well, storing neighbors for each vertex.
Final Answer:
Vec (adjacency list) -> Option A
Quick Check:
Adjacency list = Vec in Rust [OK]
Hint: Use adjacency list (Vec of Vec) for graph edges [OK]
Common Mistakes:
Using HashMap which is unrelated
Using simple Vec<usize> which can't store edges
Using String which is not a graph structure
3. What is the output of the following Rust code snippet that finds articulation points in a graph?
D. Using unwrap() on parent[u] without checking if it is Some
Solution
Step 1: Check unwrap usage on parent[u]
parent[u] may be None for root node, unwrap() causes panic if None.
Step 2: Identify safe handling
Code should check if parent[u] is Some before unwrap or handle root separately.
Final Answer:
Using unwrap() on parent[u] without checking if it is Some -> Option D
Quick Check:
Unsafe unwrap on Option causes runtime panic [OK]
Hint: Check Option unwrap safety for root node [OK]
Common Mistakes:
Ignoring root node parent None case
Assuming unwrap() is always safe
Missing visited marking (actually present here)
5. Given a graph with multiple disconnected components, how should the articulation points algorithm be adapted in Rust to find all articulation points?
hard
A. Run DFS from every unvisited vertex to cover all components
B. Run DFS only from vertex 0 assuming graph is connected
C. Run BFS instead of DFS for articulation points
D. Ignore disconnected components as they have no articulation points
Solution
Step 1: Understand disconnected graph scenario
Articulation points can exist in any component, so all must be checked.
Step 2: Adapt algorithm to run DFS on all components
Run DFS from every unvisited vertex to cover all disconnected parts.
Final Answer:
Run DFS from every unvisited vertex to cover all components -> Option A
Quick Check:
Multiple DFS runs cover all components [OK]
Hint: Run DFS on all unvisited nodes for full coverage [OK]
Common Mistakes:
Assuming graph is always connected
Using BFS which doesn't track articulation points easily
Ignoring disconnected components
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.