quality:corruption
Algorithm

The aforementioned use of depth-first search to find a cycle can be described as follows:

where

For undirected graphs, "neighbour" means all vertices connected to v, except for the one that recursively called DFS(v). This omission prevents the algorithm from finding a trivial cycle of the form v → w → v; these exist in every undirected graph with at least one edge.

A variant using breadth-first search instead will find a cycle of the smallest possible length.