Algorithm Search⌘K

Proofs: Dominator tree

These are the human proofs of Dominator tree, at full length.

The dominators of a vertex are its ancestors in the dominator tree full

This proof shows: correctness, termination.

Let GG be a directed graph with vertices 0,…,n−10, \ldots, n - 1 and start vertex rr, and let RR be the set of vertices reachable from rr. For a,b∈Ra, b \in R, aa dominates bb if every path from rr to bb contains aa. All paths below start at rr. We assume that line L1 returns the correct immediate dominators; that is proved on the page of the Lengauer-Tarjan algorithm.

Lemma 1 (partial order). Dominance on RR is reflexive, transitive and antisymmetric.

Proof. Reflexive: every path to bb ends at bb. Transitive: let aa dominate bb and bb dominate cc. A path PP to cc contains bb; its prefix up to the first occurrence of bb is a path to bb, so it contains aa, and so does PP. Antisymmetric: let a≠ba \ne b and suppose both dominate each other. Take a simple path PP to aa (one exists since a∈Ra \in R). It contains bb, so bb occurs on PP before its last vertex aa. The prefix of PP up to bb is a path to bb; it must contain aa, but aa occurs on the simple path PP only at the end, after bb. Contradiction. □\square

Lemma 2 (chain). Let v∈Rv \in R, v≠rv \ne r, and let DD be the set of strict dominators of vv. Then DD is not empty, any two elements of DD are comparable under dominance, and DD has a unique element idom(v)\mathrm{idom}(v) that is dominated by every element of DD.

Proof. r∈Dr \in D. Fix a simple path PP from rr to vv. Every element of DD occurs on PP, exactly once. Let a,b∈Da, b \in D with aa before bb on PP. Suppose aa does not dominate bb: there is a path QQ to bb avoiding aa. Then QQ followed by the part of PP after bb is a path to vv; that part of PP does not contain aa, since aa occurs on PP only before bb. So we have a path to vv avoiding aa, a contradiction with a∈Da \in D. Hence aa dominates bb. So the elements of DD are totally ordered by dominance, in the order in which they occur on PP, and the last of them on PP is dominated by all others; by antisymmetry it is unique. □\square

Lemma 3 (recursive form). For v∈R∖{r}v \in R \setminus \{r\}, the set of dominators of vv is {v}∪Dom(idom(v))\{v\} \cup \mathrm{Dom}(\mathrm{idom}(v)), where Dom(x)\mathrm{Dom}(x) is the set of dominators of xx, and v∉Dom(idom(v))v \notin \mathrm{Dom}(\mathrm{idom}(v)).

Proof. If dd dominates idom(v)\mathrm{idom}(v), then dd dominates vv by transitivity, since idom(v)\mathrm{idom}(v) dominates vv. Conversely, a dominator d≠vd \ne v of vv is in DD and, by Lemma 2, dominates idom(v)\mathrm{idom}(v). Finally vv does not dominate idom(v)\mathrm{idom}(v), by antisymmetry, since idom(v)≠v\mathrm{idom}(v) \ne v dominates vv. □\square

Lemma 4 (the tree). The edges v→idom(v)v \to \mathrm{idom}(v) for v∈R∖{r}v \in R \setminus \{r\} form a tree on RR rooted at rr, and for every v∈Rv \in R, Dom(v)\mathrm{Dom}(v) is the set of ancestors of vv in that tree.

Proof. By Lemma 3, ∣Dom(idom(v))∣=∣Dom(v)∣−1|\mathrm{Dom}(\mathrm{idom}(v))| = |\mathrm{Dom}(v)| - 1. So following idom from vv strictly decreases the size of the dominator set, which is at least 1, and the walk ends after finitely many steps at the only vertex without an idom, rr. There is no cycle, every vertex other than rr has one parent, so the edges form a tree rooted at rr. By induction on ∣Dom(v)∣|\mathrm{Dom}(v)|: Dom(r)={r}\mathrm{Dom}(r) = \{r\} (if dd dominates rr, the path consisting of rr alone contains dd), which is the set of ancestors of rr; and for v≠rv \ne r, Lemma 3 gives Dom(v)={v}∪\mathrm{Dom}(v) = \{v\} \cup the ancestors of idom(v)\mathrm{idom}(v), which are the ancestors of vv. □\square

Lemma 5 (the walk). Lines L3 to L7 terminate, and afterwards, for a,b∈Ra, b \in R, aa is an ancestor of bb in the tree if and only if tin[a]≤tin[b]tin[a] \le tin[b] and tout[b]≤tout[a]tout[b] \le tout[a].

Proof. Each tree vertex is pushed with phase enter once, by its parent (or initially, for rr), and once with phase exit, so the loop runs 2∣R∣2|R| times. The stack discipline makes this a preorder walk: when (v,enter)(v, \text{enter}) is popped, the entries for the subtree of vv are pushed above (v,exit)(v, \text{exit}), so all of them are popped before it. So the vertices of the subtree of vv get the consecutive entry times tin[v],…,tin[v]+s(v)−1tin[v], \ldots, tin[v] + s(v) - 1, where s(v)s(v) is the subtree size, and tout[v]=tin[v]+s(v)tout[v] = tin[v] + s(v). If aa is an ancestor of bb, bb's entry time lies in aa's range and bb's range is inside aa's, which gives both inequalities. If not, the subtrees of aa and bb are disjoint or bb is a proper ancestor of aa; in the first case their ranges are disjoint, so the two inequalities cannot both hold, and in the second tin[b]<tin[a]tin[b] < tin[a]. □\square

Theorem. DOMINATES(a,b)(a, b) returns true exactly when aa dominates bb, DOMINATORS(v)(v) returns exactly the dominators of vv, and all operations terminate.

Proof. If aa or bb is not in RR, aa does not dominate bb under our convention, and line L8 returns false. Otherwise, by Lemma 4, aa dominates bb exactly when aa is an ancestor of bb, and by Lemma 5 that is the test of line L9. Line L10 follows idom from vv to rr, which terminates by Lemma 4 and lists the ancestors of vv, that is, Dom(v)\mathrm{Dom}(v). For v∉Rv \notin R the implementation returns the empty list. ■\blacksquare

Back to Dominator tree