Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the discovery time for each node.
DSA Python
disc = [-1] * [1]
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or n without defining n.
Using graph directly instead of its length.
✗ Incorrect
We use the length of the graph (number of nodes) to create the discovery time list initialized with -1.
2fill in blank
mediumComplete the code to update the low time of the current node after visiting a neighbor.
DSA Python
low[u] = min(low[u], [1][v])
Attempts:
3 left
💡 Hint
Common Mistakes
Using disc[v] instead of low[v].
Using parent[v] which is not a time value.
✗ Incorrect
We update low[u] with the minimum of its current low[u] and low[v] of the neighbor.
3fill in blank
hardFix the error in the condition to check if a node is an articulation point for a non-root node.
DSA Python
if parent[u] != -1 and low[v] >= [1][u]: ap[u] = True
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing low[v] with low[u] instead of disc[u].
Using parent[u] which is not a time value.
✗ Incorrect
We compare low[v] with disc[u] to check if u is an articulation point.
4fill in blank
hardFill both blanks to correctly check if the root node is an articulation point.
DSA Python
if parent[u] == -1 and [1] > 1: ap[u] = [2]
Attempts:
3 left
💡 Hint
Common Mistakes
Setting ap[u] to False instead of True.
Checking children <= 1 instead of > 1.
✗ Incorrect
The root node is an articulation point if it has more than one child, so we check children > 1 and set ap[u] to True.
5fill in blank
hardFill all three blanks to correctly implement the DFS function header and recursive call.
DSA Python
def dfs(u, [1], [2], [3]): # function body for v in graph[u]: if disc[v] == -1: dfs(v, parent, disc, low)
Attempts:
3 left
💡 Hint
Common Mistakes
Missing parent parameter.
Passing visited instead of low.
✗ Incorrect
The dfs function takes parameters u, parent, disc, and low. The recursive call passes parent, disc, and low.
