A bridge is an edge in a graph that, if removed, increases the number of connected components. It disconnects part of the graph.
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 nodes. An edge is a bridge if the low value of the connected node is greater than the discovery time of the current node.
Click to reveal answer
intermediate
In Tarjan's algorithm, what does the 'low' value represent?
The 'low' value of a node is the earliest discovery time reachable from that node or its descendants, including back edges.
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 v and its descendants cannot reach u or any ancestor of u via a back edge, so edge (u, v) is a bridge.
Click to reveal answer
beginner
What data structures are commonly used in Tarjan's algorithm for bridges?
Arrays or slices to store discovery times, low values, a visited set, and adjacency lists for the graph representation.
Click to reveal answer
What happens if you remove a bridge edge from a graph?
AThe graph remains connected
BThe graph becomes disconnected
CThe graph becomes a tree
DThe graph has more edges
✗ Incorrect
Removing a bridge edge increases the number of connected components, disconnecting the graph.
In Tarjan's algorithm, what does the discovery time represent?
AThe number of edges in the graph
BThe total number of nodes
CThe order in which nodes are visited in DFS
DThe depth of the node in the graph
✗ Incorrect
Discovery time is the order number when a node is first visited during DFS.
Which condition indicates an edge (u, v) is a bridge in Tarjan's algorithm?
Alow[v] > disc[u]
Blow[u] > disc[v]
Cdisc[u] > disc[v]
Dlow[u] == low[v]
✗ Incorrect
If low[v] is greater than disc[u], edge (u, v) is a bridge.
What is the time complexity of Tarjan's algorithm for finding bridges?
AO(log V)
BO(V^2)
CO(E^2)
DO(V + E)
✗ Incorrect
Tarjan's algorithm runs in linear time relative to vertices and edges.
Which graph traversal method is used in Tarjan's algorithm?
ADepth-First Search (DFS)
BBreadth-First Search (BFS)
CDijkstra's Algorithm
DPrim's Algorithm
✗ Incorrect
Tarjan's algorithm uses DFS to explore the graph.
Explain how Tarjan's algorithm finds bridges in a graph step-by-step.
Think about how DFS helps track back edges and earliest reachable nodes.
You got /4 concepts.
Describe the role of 'low' values in detecting bridges and how they differ from discovery times.
Focus on what 'low' tells us about connectivity beyond the DFS tree.
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 identify edges that, if removed, increase the number of connected components
B. To find the shortest path between two nodes
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 identify edges that, if removed, increase the number of connected components -> Option A
Quick Check:
Bridges = edges increasing components when removed [OK]
Hint: Bridges split graph if removed, Tarjan finds them fast [OK]
Common Mistakes:
Confusing bridges with cycles
Thinking Tarjan finds shortest paths
Mixing bridges with node counts
2. Which of the following Go code snippets correctly declares a slice to store adjacency lists for a graph with n nodes?
easy
A. adj := make([]int, n)
B. adj := make([][]int, n)
C. adj := [][]int{n}
D. adj := make([]int, 0, n)
Solution
Step 1: Understand adjacency list representation
Adjacency list for n nodes is a slice of slices: each node has a slice of connected nodes.
Step 2: Correct Go syntax for adjacency list
make([][]int, n) creates a slice of n slices of ints, perfect for adjacency lists.
Final Answer:
adj := make([][]int, n) -> Option B
Quick Check:
Adjacency list = slice of slices [OK]
Hint: Adjacency list needs slice of slices, not flat slice [OK]
Common Mistakes:
Using make([]int, n) which is flat slice
Incorrect slice literal syntax
Confusing capacity with length
3. Consider the following Go code snippet implementing part of Tarjan's algorithm for bridges. What will be the output when run on the graph edges: (0-1), (1-2), (2-0), (1-3)?
package main
import "fmt"
var (
time int
adj [][]int
disc []int
low []int
visited []bool
)
func dfs(u, parent int) {
visited[u] = true
disc[u] = time
low[u] = time
time++
for _, v := range adj[u] {
if v == parent {
continue
}
if !visited[v] {
dfs(v, u)
if low[v] > disc[u] {
fmt.Printf("Bridge found: %d - %d\n", u, v)
}
if low[v] < low[u] {
low[u] = low[v]
}
} else {
if disc[v] < low[u] {
low[u] = disc[v]
}
}
}
}
func main() {
n := 4
adj = make([][]int, n)
adj[0] = []int{1, 2}
adj[1] = []int{0, 2, 3}
adj[2] = []int{0, 1}
adj[3] = []int{1}
disc = make([]int, n)
low = make([]int, n)
visited = make([]bool, n)
dfs(0, -1)
}
medium
A. Bridge found: 2 - 0
B. Bridge found: 0 - 1
Bridge found: 1 - 3
C. No bridges found
D. Bridge found: 1 - 3
Solution
Step 1: Analyze the graph structure
The graph has a triangle between nodes 0,1,2 and a single edge from 1 to 3. The triangle edges are not bridges because removing them doesn't disconnect the graph.
Step 2: Identify bridges using Tarjan's logic
Edge 1-3 is a bridge because removing it disconnects node 3. The code prints "Bridge found: 1 - 3" only.
Final Answer:
Bridge found: 1 - 3 -> Option D
Quick Check:
Only edge 1-3 disconnects graph [OK]
Hint: Triangle edges are not bridges; check leaf edges [OK]
Common Mistakes:
Marking triangle edges as bridges
Ignoring parent check in DFS
Confusing discovery and low values
4. The following Go code attempts to find bridges using Tarjan's algorithm but has a bug. What is the error?
func dfs(u, parent int) {
visited[u] = true
disc[u] = time
low[u] = time
time++
for _, v := range adj[u] {
if !visited[v] {
dfs(v, u)
if low[v] > disc[u] {
fmt.Printf("Bridge: %d - %d\n", u, v)
}
if low[v] < low[u] {
low[u] = low[v]
}
} else if v != parent {
if disc[v] < low[u] {
low[u] = disc[v]
}
}
}
}
medium
A. The time variable is not incremented
B. The else condition should check v == parent instead of v != parent
C. The parent check is missing before recursive DFS call
D. The low[u] update is done incorrectly after DFS call
Solution
Step 1: Check parent skipping logic
The code does not skip the parent node before calling DFS recursively, which can cause revisiting the parent and incorrect low values.
Step 2: Identify missing parent check before DFS
Correct code should have "if v == parent { continue }" before DFS call to avoid revisiting parent edge.
Final Answer:
The parent check is missing before recursive DFS call -> Option C
Quick Check:
Skip parent before DFS to avoid cycles [OK]
Hint: Always skip parent node before DFS recursion [OK]
Common Mistakes:
Confusing parent check placement
Not incrementing time variable
Misusing else if condition
5. Given a connected undirected graph with n nodes and m edges, how can Tarjan's algorithm be adapted to find all bridges efficiently? Choose the best approach.
hard
A. Use DFS once from any node, track discovery and low times, and identify edges where low[v] > disc[u]
B. Remove edges one by one and check connectivity each time
C. Use BFS to find shortest paths and mark edges not in shortest paths as bridges
D. Run DFS from each node separately without tracking discovery times
Solution
Step 1: Understand Tarjan's algorithm approach
Tarjan's algorithm uses a single DFS traversal from any node, tracking discovery and low times to find bridges efficiently.
Step 2: Identify condition for bridges
An edge u-v is a bridge if low[v] > disc[u], meaning v cannot reach u or its ancestors without that edge.
Final Answer:
Use DFS once from any node, track discovery and low times, and identify edges where low[v] > disc[u] -> Option A
Quick Check:
Single DFS + low/disc times = bridges [OK]
Hint: Single DFS with low/disc times finds bridges fast [OK]
Common Mistakes:
Running DFS multiple times unnecessarily
Using BFS which doesn't track low times
Brute force edge removal checking connectivity
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.