Data Structures & AlgorithmsVery hardICPC regional · graph theory

Problem: Which problem asks for the length of the shortest cycle in an undirected unweighted graph?

  1. A. Kruskal's algorithm
  2. B. Gale-Shapley
  3. C. Bellman-Ford
  4. D. BFS from every vertex, tracking the first non-tree edge

Correct answer: D. BFS from every vertex, tracking the first non-tree edge

BFS from each vertex detects non-tree edges that close the shortest cycles through it.

More Coding Interview Problems questions

Exams that ask this topic