DFS: Online edge classification

Dependencies:

  1. DFS: Edge classification
  2. DFS: Parenthesis theorem

When an edge $(u, v)$ is explored during DFS, it can be classified in constant time as as follows:

Proof

If $v$ is white, $π(v)$ will be set to $u$ and visit(v) will be called. This will make $(u, v)$ a tree edge.

If $v$ is gray, it means visit(v) is on the call stack. Since visit(u) is the top entry on the call stack when $(u, v)$ is explored, visit(u) was called during visit(v). This means $u$ is a descendant of $v$ in the DFS forest, so $(u, v)$ is a back edge.

If $v$ is black, it means visit(v) finished before $(u, v)$ was explored. Therefore, $f(v) < f(u)$. By the parenthesis theorem, there can be 2 cases:

Dependency for:

  1. DFS: low

Info:

Transitive dependencies:

  1. /sets-and-relations/equivalence-classes
  2. /sets-and-relations/relation-composition-is-associative
  3. /sets-and-relations/equivalence-relation
  4. Graph
  5. Transpose of a graph
  6. Path in Graph
  7. Rooted tree
  8. Forest
  9. Properties of DFS
  10. DFS: Edge classification
  11. DFS: Parenthesis theorem