A bridge is an edge in a graph that, if removed, increases the number of connected components. It means the edge is critical for keeping the graph connected.
Click to reveal answer
intermediate
What is the main idea behind Tarjan's algorithm for finding bridges?
Tarjan's algorithm uses a depth-first search (DFS) to assign discovery times and low values to each vertex. An edge is a bridge if the low value of the connected vertex is greater than the discovery time of the current vertex.
Click to reveal answer
intermediate
In Tarjan's algorithm, what does the 'low' value represent?
The 'low' value of a vertex is the earliest discovery time reachable from that vertex or its descendants by following zero or more tree edges and then possibly one back edge.
Click to reveal answer
advanced
Why do we compare low[v] > disc[u] to find a bridge between u and v?
If low[v] > disc[u], it means there is no back edge from v or its descendants to u or any ancestor of u. So, removing edge (u, v) disconnects the graph, making it a bridge.
Click to reveal answer
beginner
What is the time complexity of Tarjan's algorithm for finding bridges?
The time complexity is O(V + E), where V is the number of vertices and E is the number of edges, because it uses a single DFS traversal.
Click to reveal answer
What does a bridge in a graph do?
ADisconnects the graph if removed
BConnects two vertices with multiple paths
CIs part of a cycle
DIs a vertex with highest degree
✗ Incorrect
A bridge is an edge that, if removed, increases the number of connected components, effectively disconnecting the graph.
In Tarjan's algorithm, what does the discovery time represent?
AThe order in which vertices are visited in DFS
BThe number of edges connected to a vertex
CThe lowest vertex reachable from a vertex
DThe total number of vertices in the graph
✗ Incorrect
Discovery time is the timestamp when a vertex is first visited during DFS.
Which condition identifies an edge (u, v) as a bridge in Tarjan's algorithm?
Adisc[u] > disc[v]
Blow[u] > disc[v]
Clow[v] > disc[u]
Dlow[u] == low[v]
✗ Incorrect
If low[v] > disc[u], edge (u, v) is a bridge because v or its descendants cannot reach u or its ancestors.
What data structure is primarily used in Tarjan's algorithm for bridges?
AHash Map
BQueue
CPriority Queue
DDepth-First Search (DFS) stack
✗ Incorrect
Tarjan's algorithm uses DFS traversal and recursion stack to explore vertices.
What is the time complexity of Tarjan's algorithm for finding bridges?
AO(E^2)
BO(V + E)
CO(V^2)
DO(log V)
✗ Incorrect
Tarjan's algorithm runs in linear time relative to vertices and edges, O(V + E).
Explain how Tarjan's algorithm finds bridges in a graph using discovery and low values.
Think about how DFS helps track back edges and earliest reachable vertices.
You got /4 concepts.
Describe why removing a bridge edge increases the number of connected components in a graph.
Consider what happens to connectivity if that edge is gone.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of Tarjan's algorithm when finding bridges in a graph?
easy
A. To find the shortest path between two nodes
B. To find edges that, if removed, increase the number of connected components
C. To detect cycles in a graph
D. To count the total number of nodes in the graph
Solution
Step 1: Understand the definition of a bridge
A bridge is an edge that, when removed, increases the number of connected components in a graph.
Step 2: Purpose of Tarjan's algorithm for bridges
Tarjan's algorithm efficiently finds all such edges (bridges) in a graph using DFS and low-link values.
Final Answer:
To find edges that, if removed, increase the number of connected components -> Option B
Quick Check:
Bridges = edges increasing components when removed [OK]
Hint: Bridges disconnect graph if removed [OK]
Common Mistakes:
Confusing bridges with cycles
Thinking it finds shortest paths
Assuming it counts nodes
2. Which of the following is the correct way to initialize the discovery time and low arrays in Tarjan's algorithm in Python?
easy
A. discovery = [-1] * n; low = [-1] * n
B. discovery = [0] * n; low = [0] * n
C. discovery = list(range(n)); low = list(range(n))
D. discovery = None; low = None
Solution
Step 1: Understand initialization purpose
Discovery and low arrays store times; initializing with -1 means unvisited nodes.
Step 2: Choose correct initialization
Using [-1] * n marks all nodes as unvisited initially, which is standard practice.
Final Answer:
discovery = [-1] * n; low = [-1] * n -> Option A
Quick Check:
Unvisited nodes marked with -1 [OK]
Hint: Use -1 to mark unvisited nodes [OK]
Common Mistakes:
Initializing with zeros (means visited)
Using range values (incorrect meaning)
Setting to None (causes errors)
3. What will be the output bridges for the following undirected graph using Tarjan's algorithm?
Nodes 0,1,2 form a triangle (cycle), so no bridges there. Edges (2,3) and (3,4) connect to nodes outside the cycle.
Step 2: Identify bridges
Removing edge (2,3) or (3,4) disconnects the graph, so these are bridges.
Final Answer:
[(2, 3), (3, 4)] -> Option C
Quick Check:
Edges breaking connectivity = bridges [OK]
Hint: Edges outside cycles are likely bridges [OK]
Common Mistakes:
Marking cycle edges as bridges
Missing edges connecting components
Confusing node pairs order
4. Identify the bug in this Tarjan's algorithm snippet for finding bridges:
def dfs(u, parent):
visited[u] = True
disc[u] = time
low[u] = time
time += 1
for v in graph[u]:
if not visited[v]:
dfs(v, u)
low[u] = min(low[u], low[v])
if low[v] > disc[u]:
bridges.append((u, v))
elif v != parent:
low[u] = min(low[u], disc[v])
medium
A. visited array is not updated correctly
B. The condition low[v] > disc[u] should be low[v] >= disc[u]
C. The parent check should be if v == parent, not v != parent
D. time variable is not declared global or passed, causing UnboundLocalError
Solution
Step 1: Check variable usage
The variable 'time' is incremented inside dfs but not declared global or passed, causing an error.
Step 2: Understand Python variable scope
Without 'global time' or passing time as argument, Python treats 'time' as local, causing UnboundLocalError.
Final Answer:
time variable is not declared global or passed, causing UnboundLocalError -> Option D
Quick Check:
Modify time scope to fix error [OK]
Hint: Declare time global or pass as argument [OK]