Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the discovery time for the current node in Tarjan's algorithm.
DSA Rust
disc[u] = [1]; low[u] = time; time += 1;
Attempts:
3 left
💡 Hint
Common Mistakes
Setting discovery time to 0 or node index instead of current time.
Forgetting to assign low[u] the same initial value.
✗ Incorrect
The discovery time for node u is set to the current time counter before incrementing it.
2fill in blank
mediumComplete the code to update the low value of the current node after visiting a neighbor in Tarjan's algorithm.
DSA Rust
low[u] = [1](low[u], low[v]);Attempts:
3 left
💡 Hint
Common Mistakes
Using max instead of min causes incorrect bridge detection.
Using sum or abs is not meaningful here.
✗ Incorrect
The low value is updated to the minimum of its current low and the neighbor's low value.
3fill in blank
hardFix the error in the condition that detects a bridge edge in Tarjan's algorithm.
DSA Rust
if low[v] [1] disc[u] { bridges.push((u, v)); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '==' causes incorrect bridge detection.
Using '!=' is not a valid condition for bridges.
✗ Incorrect
An edge (u, v) is a bridge if low[v] > disc[u], meaning v cannot reach an ancestor of u.
4fill in blank
hardFill both blanks to correctly skip the parent node and update low value for back edges.
DSA Rust
for &v in graph[u].iter() { if v == [1] { continue; } if disc[v] != -1 { low[u] = [2](low[u], disc[v]); } }
Attempts:
3 left
💡 Hint
Common Mistakes
Not skipping the parent node causes incorrect low values.
Using max instead of min leads to wrong bridge detection.
✗ Incorrect
We skip the parent node to avoid trivial cycles, and update low[u] with the minimum of low[u] and disc[v] for back edges.
5fill in blank
hardFill all three blanks to complete the recursive DFS call and update low value after recursion.
DSA Rust
for &v in graph[u].iter() { if v != [1] { if disc[v] == -1 { dfs(v, u, disc, low, graph, bridges, [2]); low[u] = [3](low[u], low[v]); } } }
Attempts:
3 left
💡 Hint
Common Mistakes
Passing wrong variable instead of time causes incorrect discovery times.
Using max instead of min breaks bridge detection logic.
✗ Incorrect
We recurse on neighbors not equal to parent, pass the current time counter, and update low[u] with the minimum of low[u] and low[v].
