DFS: Difference between revisions
From Rice Wiki
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
{{Infobox Algorithm|runtime=O(V + E)|space=O(V)|class=[[Graph Algorithms]]}} | |||
= DFS = | = DFS = | ||
Revision as of 23:34, 5 March 2024
DFS
Used for cycle detection
Test link to another page: First_Page
Implementation
DFS_visit(u) {
time = time + 1
d[u] = time
color[u] = 'grey'
for each v in adj[u] {
if color[u] == white
DFS_visit(u)
}
f[u] = time++
color[u] = black
}
