Detect a cycle in a Graph
Background
If graph is a tree, there must be n - 1 edges when vertex is n.
There must be a cycle if the number of edges is greater or equal to n
Detect a cycle with union find?
How to check cycle?
Count Edges
undirected only
DFS
both possible
directed - white/gray/black
undirected - true/false
Union Find - disjoint set
undirected only
no self loop
Last updated