Undirected Graph Cycle Detection
In an undirected graph, DFS can detect a cycle by tracking the parent of each vertex. When visiting a neighbor that is already visited and is not the current vertex's parent, a cycle exists. Another approach is Union-Find: if an edge connects two vertices already in the same set, that edge creates a cycle.
DFS uses a parent check.
Union-Find works particularly well when processing an edge list.
DFS complexity: O(V+E).
Union-Find is approximately O(E alpha(V)) with path compression and union by rank.