Cycle Detection
Undirected: an edge to a seen vertex other than the parent. Directed: an edge to a vertex still on the DFS path.
DFS Checks: An undirected cycle
At 0, edge to 1. 1 is unseen, so enter it with parent 0.
Cost
- Best
- O(V + E)
- Average
- O(V + E)
- Worst
- O(V + E)
- Space
- O(V)
Before this
Variants
- Undirected (DFS or Union-Find)
- Directed (DFS colours)
Related
Leads to
Topics that need this one first.
Taught by the same lesson
DFS Checks covers these too, in the same run.