DFS: Difference between revisions

From Rice Wiki
No edit summary
Tag: Manual revert
No edit summary
Line 8: Line 8:


<code>
<code>
DFS_visit(u) {
    DFS_visit(u) {
    time = time + 1
        time = time + 1
    d[u] = time
        d[u] = time
    color[u] = 'grey'
        color[u] = 'grey'
    for each v in adj[u] {
        for each v in adj[u] {
        if color[u] == white
            if color[u] == white
            DFS_visit(u)
                DFS_visit(u)
        }
        f[u] = time++
        color[u] = black
     }
     }
    f[u] = time++
    color[u] = black
}
</code>
</code>

Revision as of 01:14, 28 February 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
   }