Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Course Schedule II
Bookmark
DFS
BFS (Kahn's)
Input
Example 1
Example 2
With Cycle
Custom
numCourses
=
4
,
prerequisites
=
[[1,0],[2,0],[3,1],[3,2]]
state
U
0
U
1
U
2
U
3
C0
C0
C1
C1
C2
C2
C3
C3
call stack
order
state
U
0
U
1
U
2
U
3
C0
C0
C1
C1
C2
C2
C3
C3
call stack
order
state
V
0
U
1
U
2
U
3
C0
C0
C1
C1
C2
C2
C3
C3
current
dfs(C0)
top
call stack
order
state
V
0
U
1
U
2
U
3
C0
C0
C1
C1
C2
C2
C3
C3
current
dfs(C0)
top
call stack
order
state
V
0
V
1
U
2
U
3
C0
C0
C1
C1
C2
C2
C3
C3
current
dfs(C0)
dfs(C1)
top
call stack
order
state
V
0
V
1
U
2
D
3
C0
C0
C1
C1
C2
C2
C3
C3
current
dfs(C0)
dfs(C1)
dfs(C3)
top
call stack
order
state
V
0
D
1
U
2
D
3
C0
C0
C1
C1
C2
C2
C3
C3
1
current
dfs(C0)
dfs(C1)
top
call stack
order
3
state
V
0
D
1
V
2
D
3
C0
C0
C1
C1
1
C2
C2
C3
C3
2
current
dfs(C0)
dfs(C2)
top
call stack
order
1
3
state
V
0
D
1
V
2
D
3
C0
C0
C1
C1
1
C2
C2
C3
C3
2
current
dfs(C0)
dfs(C2)
top
call stack
order
1
3
state
V
0
D
1
D
2
D
3
C0
C0
C1
C1
2
C2
C2
1
C3
C3
3
current
dfs(C0)
dfs(C2)
top
call stack
order
2
1
3
state
D
0
D
1
D
2
D
3
C0
C0
1
C1
C1
3
C2
C2
2
C3
C3
4
call stack
order
0
2
1
3
return [0, 2, 1, 3]
algo
master
.
io
Step:
Initialize state array (U=unvisited, V=visiting, D=done)
0 / 24
Input
Example 1
Example 2
With Cycle
Custom
numCourses
=
4
,
prerequisites
=
[[1,0],[2,0],[3,1],[3,2]]
0 / 24
algo
master
.
io
Step:
Initialize state array (U=unvisited, V=visiting, D=done)