Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Find Eventual Safe States
Bookmark
DFS
BFS (Kahn's)
Input
Cycle
All Safe
Custom
graph
=
[[1,2],[2,3],[4],[0],[]]
0
1
2
3
4
Call Stack
State: (U=Unvisited, V=Visiting, D=Done)
U
0
U
1
U
2
U
3
U
4
Topological Order:
Legend:
Unvisited
Processing
Visiting
Visited
Cycle
0
1
2
3
4
Call Stack
State: (U=Unvisited, V=Visiting, D=Done)
U
0
U
1
U
2
U
3
U
4
Topological Order:
Legend:
Unvisited
Processing
Visiting
Visited
Cycle
0
1
2
3
4
dfs(0)
top
Call Stack
State: (U=Unvisited, V=Visiting, D=Done)
V
0
U
1
U
2
U
3
U
4
Topological Order:
Legend:
Unvisited
Processing
Visiting
Visited
Cycle
0
1
2
3
4
dfs(0)
dfs(1)
top
Call Stack
State: (U=Unvisited, V=Visiting, D=Done)
V
0
V
1
U
2
U
3
U
4
Topological Order:
Legend:
Unvisited
Processing
Visiting
Visited
Cycle
0
1
2
3
4
dfs(0)
dfs(1)
dfs(2)
top
Call Stack
State: (U=Unvisited, V=Visiting, D=Done)
V
0
V
1
V
2
U
3
U
4
Topological Order:
Legend:
Unvisited
Processing
Visiting
Visited
Cycle
0
1
2
3
4
dfs(0)
dfs(1)
dfs(2)
dfs(4)
top
Call Stack
State: (U=Unvisited, V=Visiting, D=Done)
V
0
V
1
V
2
U
3
V
4
Topological Order:
Legend:
Unvisited
Processing
Visiting
Visited
Cycle
0
1
2
3
4
dfs(0)
dfs(1)
dfs(2)
top
Call Stack
State: (U=Unvisited, V=Visiting, D=Done)
V
0
V
1
S
2
U
3
S
4
Topological Order:
Legend:
Unvisited
Processing
Visiting
Visited
Cycle
0
1
2
3
4
dfs(0)
dfs(1)
dfs(3)
top
Call Stack
State: (U=Unvisited, V=Visiting, D=Done)
V
0
V
1
S
2
V
3
S
4
Topological Order:
Legend:
Unvisited
Processing
Visiting
Visited
Cycle
0
1
2
3
4
dfs(0)
dfs(1)
dfs(3)
top
Call Stack
State: (U=Unvisited, V=Visiting, D=Done)
V
0
V
1
S
2
V
3
S
4
Topological Order:
Legend:
Unvisited
Processing
Visiting
Visited
Cycle
0
1
2
3
4
dfs(0)
dfs(1)
top
Call Stack
State: (U=Unvisited, V=Visiting, D=Done)
V
0
X
1
S
2
X
3
S
4
Topological Order:
Legend:
Unvisited
Processing
Visiting
Visited
Cycle
0
1
2
3
4
Call Stack
State: (U=Unvisited, V=Visiting, D=Done)
X
0
X
1
S
2
X
3
S
4
Topological Order:
2
4
Legend:
Unvisited
Processing
Visiting
Visited
Cycle
algo
master
.
io
Step:
Initialize state array (U=unvisited, V=visiting, S=safe, X=unsafe)
0 / 27
Input
Cycle
All Safe
Custom
graph
=
[[1,2],[2,3],[4],[0],[]]
0 / 27
algo
master
.
io
Step:
Initialize state array (U=unvisited, V=visiting, S=safe, X=unsafe)