[prev] 9 [next]

Checking for Cycles

A graph has a cycle if
  • it has a path of length > 1
  • with start vertex src = end vertex dest
Function  bool hasCycle(Graph g)  tells us this.

We are not required to give the path, just indicate its presence.

[Diagram:Pics/graphs/cycle-ex.png]