2

Suppose we construct a tree on a graph G with breadth-first search (BFS) and determine that there is no edge in the graph that connects nodes that belong to the same layer in the BFS tree. Does that mean that the graph has no cycle?

Michael Laszlo
  • 12,009
  • 2
  • 29
  • 47

1 Answers1

0

No, it does not. Consider the following directed graph:

enter image description here

If we start BFS from node 1, the search ends at node 3. Each vertex is in a separate layer, so there is no edge in the graph that connects nodes belonging to the same layer. However, the graph contains a cycle.

We can also construct a counterexample for undirected graphs:

enter image description here

The first layer contains node 1. The second layer contains nodes 2 and 4. The third layer contains node 3. The only layer with more than one node is the second layer, and its two nodes are not connected by an edge. Once again, there is no edge in the graph between nodes in the same layer, yet the graph contains a cycle.

Michael Laszlo
  • 12,009
  • 2
  • 29
  • 47