Data Structures & AlgorithmsHardICPC regional · graph theory

Problem: Which statement about Kosaraju's algorithm for strongly connected components is correct?

  1. A. It needs a priority queue and runs in O(E log V)
  2. B. It works only on acyclic graphs
  3. C. It computes all-pairs shortest paths as a by-product
  4. 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

Exams that ask this topic