Data Structures & AlgorithmsHardICPC regional · graph theory
Problem: Which statement about Kosaraju's algorithm for strongly connected components is correct?
- A. It needs a priority queue and runs in O(E log V)
- B. It works only on acyclic graphs
- C. It computes all-pairs shortest paths as a by-product
- D. It runs two DFS passes (the second on the transposed graph in reverse finishing order) in O(V + E) time
Correct answer: D. It runs two DFS passes (the second on the transposed graph in reverse finishing order) in O(V + E) time
The first pass records finishing order, and the second pass on the reversed graph in decreasing finish time peels off the SCCs. Each pass is linear.
More Coding Interview Problems questions
- Problem: Which statement about the Edmonds-Karp maximum-flow algorithm (BFS augmenting paths) is correct?
- Problem: A road map has junctions 0–6 and two-way roads with lengths: 0-1 (4), 0-2 (1), 2-1 (2), 1-3 (5), 2-3 (8), 3-4 (3), 2-5 (10), 4-6…
- Problem: Starting with 8 singleton sets {0}..{7}, perform these unions in order: (0,1), (2,3), (1,3), (4,5), (6,7), (5,7), (3,4). After…
- Problem: A grid has '.' for open cells and '#' for walls: rows are ".#..#", ".#.##", "...#.", "##..#" and "#...." (5×5). Cells connect…
- Problem: How many simple cycles (cycles that visit no vertex twice, with 3 or more vertices) does the complete undirected graph K4 on…
- Problem: A rooted tree (root 1) has children lists: 1: [2, 3], 2: [4, 5, 6], 3: [7], 4: [], 5: [8], 6: [], 7: [9], 8: [], 9: []. How many…