A Cycle Witness in an Undirected Graph
A simple undirected graph has a cycle when some walk returns to its start through distinct edges and otherwise distinct vertices.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace a triangle
Starting A, moving to B, then C, and back to A displays a length-three cycle. Traversing A to B and immediately back uses the same edge twice and is not a simple cycle. Walks and simple paths distinguish the relevant patterns.
Use a search tree carefully
During an undirected search, a visited neighbor that is the direct parent need not indicate a cycle. A different discovered neighbor can supply a non-tree edge that closes one. See spanning discovery trees.[1]
Produce the edges that close a path
If search discovers B from A and C from B, then examines C–A in the same active branch, the path A–B–C plus C–A forms a triangle. The reverse incidence of C's parent edge C–B is expected and should be ignored. See depth-first search.
Tree path: A–B–C
Nonparent edge: C–A
Cycle witness: A–B–C–A
Keep edge identity when the graph has repeated endpoints
Ignoring every edge to the parent vertex can skip a second parallel edge. If multigraph cycles are recognized, distinguish the actual parent edge by ID. Validate the returned witness against original edges and the chosen graph convention.