Module 8 · Graphs and Trees · BFS on Graph

Cycle in an undirected graph

Every edge goes both ways, so the edge back to where we came from doesn't count. Any other neighbour that is already visited was reached a second way: that's a cycle.

Approach