Learn
Practice
Newsletter
Resources
F
Toggle theme
0
F
Toggle theme
0
Toggle menu
← Back to All Animations
Detect Cycle in Directed Graph (DFS)
Bookmark
Input
With Cycle
No Cycle (DAG)
Self Loop
Simple Cycle
Custom
n
=
5
,
edges
=
[[0,1],[1,2],[2,3],[3,1],[4,0]]
0
1
2
3
4
Legend:
WHITE
GRAY
BLACK
Cycle
algo
master
.
io
Step:
Start: Detect cycle in directed graph using DFS 3-color marking (WHITE/GRAY/BLACK)
0 / 14
Input
With Cycle
No Cycle (DAG)
Self Loop
Simple Cycle
Custom
n
=
5
,
edges
=
[[0,1],[1,2],[2,3],[3,1],[4,0]]
0 / 14
0
1
2
3
4
Legend:
WHITE
GRAY
BLACK
Cycle
algo
master
.
io
Step:
Start: Detect cycle in directed graph using DFS 3-color marking (WHITE/GRAY/BLACK)