Dominator Tree Verification and Vertex-Disjoint Paths Loukas Georgiadis 1 Robert E. Tarjan 1,2 Abstract We present a linear-time algorithm that given a flowgraph G = (V,A,r) and a tree T , checks whether T is the dominator tree of G. Also we prove that there exist two spanning trees of G, T1 and T2, such that for any vertex v the paths from r to v in T1 and T2 intersect only at the vertices that dominate v. The proof is constructive and our algorithm can build the two spanning trees in linear time. Simpler versions of our two algorithms run in O((m, n))- time, where n is the number of vertices and m is the number of arcs in G. The existence of such two spanning trees implies that we can order the calculations of the iterative algorithm for finding dominators, proposed by Allen and Cocke [2], so that it builds the dominator tree in a single iteration. 1 Introduction We consider a flowgraph G = (V,A,r), which is a directed graph such that every vertex is reachable from a distinguished start vertex r V . Let n and m be, respectively, the number vertices and arcs in G. A vertex w dominates a vertex v if every path from r to v includes w. Let dom(v) be the set of the vertices that dominate v. Obviously, r and v, the trivial dominators of v, are in dom(v). For v = r, the immediate dominator of v, denoted by d(v), is the unique vertex w = v that dominates v and is dominated by all the vertices in dom(v) v. The (immediate) dominator tree is a directed tree I rooted at r which is formed by the arcs {(d(v),v) | v V r}. A vertex w dominates v if and only if w is an ancestor of v in I [1]. Thus I is a compact representation of the dominance relation. Compilers use dominance information extensively during program analysis and optimization, for nat- ural loop detection (which enables several optimiza- tions), structural analysis [18], scheduling [19], and the computation of dependence graphs and static single- assignment forms [9]. Dominators are also used to iden- tify pairs of equivalent line faults in VLSI circuits [4]. 1 Department of Computer Science, Princeton University, Princeton NJ, 08540. E-mail: {lgeorgia,ret}@cs.princeton.edu. Research at Princeton University partially supported by the Na- tional Science Foundation, under the Aladdin Project, Grant No 112-0188-1234-12. 2 Hewlett-Packard, Palo Alto CA. There is an O((m, n))-time algorithm [16] to compute dominators that has been used in many of these applications. Here α is a functional inverse of Ackermann’s function, which is very slow-growing; for all practical purposes this algorithm runs in linear time. Indeed, it runs fast in practice [13], even though it has some conceptual complexities. There are even more complicated truly linear-time algorithms that run on random-access machines [3, 7] and on pointer ma- chines [12]. The work described here was motivated by a ques- tion Steven Weeks (private communication, 1999) asked the second author: is there a simple way to verify the correctness of a dominator tree computed by such a complicated algorithm (or any algorithm)? The relationship of verification to computation is highly problem-dependent. It is interesting, for exam- ple, to compare the situation for shortest path trees to that of minimum spanning trees. There is a very simple linear-time algorithm to verify a shortest path tree, but no linear-time algorithm to compute shortest path trees is known (for a comparison-based computation model). On the other hand, minimum spanning trees can be ver- ified in linear time [10, 15, 6], but the known methods are complicated. By combining a linear-time verifica- tion algorithm with random sampling, one can actually find a minimum spanning tree in linear time [14]. In this paper we present a linear-time algorithm to verify a dominator tree. This algorithm is simpler than the known linear-time algorithms to find domina- tor trees. Also, an O((m, n))-time version of our algorithm is simpler than the O((m, n))-time algo- rithm for finding dominators: it requires only a stan- dard set union data structure instead of a link-eval data structure [23]. Our work sheds light on the relation- ship between verification and computation of domina- tors, and we hope it will lead to a simpler linear-time algorithm to find dominators. The second part of this paper deals with a related problem involving dominators. We give a linear-time algorithm for constructing two spanning trees T 1 and T 2 of G with the following ancestor-dominance property. For any vertex v = r the paths from r to v in T 1 and T 2 intersect only at the dominators of v. The existence of such two spanning trees is an extension of a result of