Depth first search

Posted on April 11, 2015

Properties

  1. the intervals \([u.d, u.f]\) and \([v.d, v.f]\) are disjoint,
  2. the interval \([u.d, u.f]\) is a subset of the interval \([v.d, v.f]\), or
  3. the interval \([v.d, v.f]\) is a subset of the interval \([v.d, v.f]\).

Classification of edges

We can classify the edges in the graph after doing a BFS search into the following

  1. Tree edges are edges in the depth-first forest \(G_\pi\). Edge \((u,v)\) is a tree edge if \(v\) was first discovered by exploring edge \((u,v)\).
  2. Back edges are those edges \((u,v)\) connecting a vertex \(u\) to an ancestor \(v\) in an depth-first tree. We consider self-loops to be back-edges.
  3. Forward edges are those non-tree edges \((u,v)\) connecting a vertex \(u\) to a descendant \(v\) in a depth-first tree.
  4. Cross edges are all other edges.

In the DFS algorithm, one can show that following proposition, here while at edge \(u\), if we encounter the edge \((u,v)\), using the color of \(v\), we can classify the edge \((u,v)\) as follows:

  1. White indicates a tree edge,
  2. Gray indicates a Back edge,
  3. Black indicates a cross edge or forward edge.

Notes

  1. a tree edge or forward edge if and only if \(u.d < v.d < v.f < u.f\),
  2. a back edge if and only if \(v.d \le u.d < u.f \le v.f\), and
  3. a cross edge if and only if \(v.d < v.f < u.d < u.f\).