Data Structures & AlgorithmsVery hardICPC regional · Product Company SDE

Problem: In a graph with vertices 0–7 and edges 0-1, 1-2, 2-3, 3-0, 3-4, 4-5, 5-6, 6-4, 6-7, which edges lie on at least one cycle? How many such edges are there?

  1. A. 9
  2. B. 7
  3. C. 2
  4. D. 4

Correct answer: B. 7

An edge is on a cycle unless it is a bridge; the bridges are 3-4 and 6-7, so 9 − 2 = 7 edges (cycle 0-1-2-3 and triangle 4-5-6). Counting all edges gives 9, counting the bridges gives 2, and counting only the 4-cycle gives 4.

More Coding Interview Problems questions

Exams that ask this topic