0

I am given an algorithm that is supposed to find the length of the shortest cycle in an undirected graph with unit edge lengths. I have to show that the algorithm does not always work by providing a counterexample. I am having problems coming up with an example that can show that this algorithm does not always work.


Algorithm:

  • Do a depth-first search, keeping track of the level of each vertex.
  • Each time a back edge is encountered, compute the cycle length and save it if it is smaller than the shortest one previously seen.

Any suggestions/ help will be appreciated

sve
  • 4,016
  • 1
  • 16
  • 28
user3055141
  • 99
  • 1
  • 8

1 Answers1

2

Look at this graph with the given traversal:

enter image description here

When you encounter backedge e->a you note a cycle with length 5 and for e->b - a cycle with length 4. However, the answer is 3 produced by the cycle a-b-e.

sve
  • 4,016
  • 1
  • 16
  • 28