Discrete Mathsfor Engineers

Structures, proofs, and intuition

EN | PT

Depth-First Search (DFS)

Part 4 — Structural Properties & Discovery Times

Series: Depth-First Search (DFS) Part 4 of 8

4. Structural Properties & Discovery Times


Roadmap (what you will learn in this part):
  1. What discovery and finish times mean
  2. Why DFS intervals are structurally important
  3. The parenthesis theorem
  4. The white-path theorem intuition
  5. Ancestor–descendant relations in DFS trees
  6. Why these properties power later applications

Depth-First Search is more than a traversal rule. Its timestamps encode a hidden structure in the graph exploration.

In this part, we study the formal properties of discovery times, finish times, and the interval structure generated by recursion.

4.1 Discovery and Finish Times

During DFS, every vertex u receives two timestamps:

  • d[u] — the moment u is first discovered
  • f[u] — the moment the exploration of u is completed

These times satisfy:

d[u] < f[u]

for every vertex u, because a vertex must be discovered before it can be finished.

4.2 The Interval View

Each vertex defines a time interval:

[d[u], f[u]]

This interval represents the full active lifetime of u in the recursion.

Interpretation: a vertex is GRAY exactly while its interval is open.

The key structural fact is that DFS intervals are not arbitrary: they are either nested or disjoint.

4.3 Parenthesis Theorem

For any two vertices u and v, exactly one of the following holds:

  • The intervals [d[u], f[u]] and [d[v], f[v]] are disjoint
  • [d[u], f[u]] is fully contained in [d[v], f[v]]
  • [d[v], f[v]] is fully contained in [d[u], f[u]]
Why “parenthesis”? DFS behaves like properly nested parentheses: once you open a recursive call, you must close it before closing its caller.

4.4 Nesting Example

Suppose DFS discovers u, then from u discovers v.

Then the timestamps must satisfy:

d[u] < d[v] < f[v] < f[u]

So the interval of v is nested inside the interval of u.

Conclusion: descendants live entirely inside the time interval of their ancestors.

4.5 Ancestor–Descendant Criterion

In a DFS tree, vertex u is an ancestor of v if and only if:

d[u] < d[v] < f[v] < f[u]

Equivalently, the interval of v is properly nested inside the interval of u.

This gives DFS a powerful structural test: ancestry can be read directly from timestamps.

4.6 Disjoint Intervals and Separate Branches

If two vertices lie in different DFS branches, or in different DFS trees of the forest, their intervals are disjoint.

So DFS timestamps separate the graph into nested recursive regions.

Structural insight: nesting means ancestry; disjointness means separation.

4.7 White-Path Intuition

A central theorem in DFS theory states: a vertex v becomes a descendant of u in the DFS forest if and only if, at the moment u is discovered, there exists a path from u to v consisting entirely of WHITE vertices.

Intuition: DFS can only recurse through vertices that have not yet been discovered.

This theorem helps justify why DFS trees encode reachability structure in such a precise way.

4.8 Why These Properties Matter

Discovery and finish times are not decorative metadata. They are the reason DFS supports:

  • edge classification
  • cycle detection
  • topological sorting
  • strongly connected components
Takeaway: DFS turns recursive exploration into a formal structural language.

4.9 Mini Summary

  • Every vertex gets a discovery time and a finish time.
  • These define intervals [d[u], f[u]].
  • DFS intervals are either nested or disjoint.
  • Nesting characterizes ancestry in the DFS forest.
  • This structure will drive all advanced DFS applications.

Next: Part 5 — Edge Classification

Now that we understand the structural meaning of DFS timestamps, we can classify edges according to how they relate to the DFS forest.

In Part 5, we study tree edges, back edges, forward edges, and cross edges — and why they are crucial for cycle detection and graph analysis.