Fast Compatibility Testing for Phylogenies with Nested Taxa∗
Yun Deng†

David Fernández-Baca‡

arXiv:1605.02045v1 [] 6 May 2016

Abstract
Semi-labeled trees are phylogenies whose internal nodes may be labeled by higher-order taxa. Thus,
a leaf labeled Mus musculus could nest within a subtree whose root node is labeled Rodentia, which itself
could nest within a subtree whose root is labeled Mammalia. Suppose we are given collection P of semilabeled trees over various subsets of a set of taxa. The ancestral compatibility problem asks whether there
is a semi-labeled tree T that respects the clusterings and the ancestor/descendant relationships implied
by the trees in P. We give a Õ(MP ) algorithm for the ancestral compatibility problem, where MP is the
total number of nodes and edges in the trees in P. Unlike the best previous algorithm, the running time
of our method does not depend on the degrees of the nodes in the input trees.

1

Introduction

In the tree compatibility problem, we are given a collection P = {T1 , . . . , Tk } of rooted phylogenetic trees
with partially overlapping taxon sets. P is called a profile and the trees in P are the input trees. The question
is whether there exists a tree T whose taxon set is the union of the taxon sets of the input trees, such that
T exhibits the clusterings implied by the input trees. That is, if two taxa are together in a subtree of some
input tree, then they must also be together in some subtree of T . The tree compatibility problem has been
studied for over three decades [1, 8, 10, 20].
In the original version of the tree compatibility problem, only the leaves of the input trees are labeled.
Here we study a generalization, called ancestral compatibility, in which taxa may be nested. That is, the
internal nodes may also be labeled; these labels represent higher-order taxa, which are, in effect, sets of
taxa. Thus, for example, an input tree may contain the taxon Glycine max (soybean) nested within a subtree
whose root is labeled Fabaceae (the legumes), itself nested within an Angiosperm subtree. Note that leaves
themselves may be labeled by higher-order taxa. The question now is whether there is a tree T whose taxon
set is the union of the taxon sets of the input trees, such that T exhibits not only the clusterings among
the taxa, but also the ancestor/descendant relationships among taxa in the input trees. Our main result is a
Õ(MP ) algorithm for the compatibility problem for trees with nested taxa, where MP is the total number
of nodes and edges in the trees in P.
Background. The tree compatibility problem is a basic special case of the supertree problem. A supertree
method is a way to synthesize a collection of phylogenetic trees with partially overlapping taxon sets into a
single supertree that represents the information in the input trees. The supertree approach, proposed in the
early 90s [2, 15], has been used successfully to build large-scale phylogenies [4].
∗

Supported in part by the National Science Foundation under grant CCF-1422134.
Department of Computer Science, Iowa State University, Ames, IA 50011, USA, yundeng@iastate.edu
‡
Department of Computer Science, Iowa State University, Ames, IA 50011, USA, fernande@iastate.edu.
†

1

The original supertree methods were limited to input trees where only the leaves are labeled. Page [13]
was among the first to note the need to handle phylogenies where internal nodes are labeled, and taxa are
nested. A major motivation is the desire to incorporate taxonomies as input trees in large-scale supertree
analyses, as way to circumvent one of the obstacles to building comprehensive phylogenies: the limited
taxonomic overlap among different phylogenetic studies [16]. Taxonomies group organisms according to
a system of taxonomic rank (e.g., family, genus, and species); two examples are the NCBI taxonomy [17]
and the Angiosperm taxonomy [21]. Taxonomies spanning a broad range of taxa provide structure and
completeness that might be hard to obtain otherwise. A recent example of the utility of taxonomies is the
Open Tree of Life, a draft phylogeny for over 2.3 million species [11].
Taxonomies are not, strictly speaking, phylogenies. In particular, their internal nodes and some of their
leaves are labeled with higher-order taxa. Nevertheless, taxonomies have many of the same mathematical
characteristics as phylogenies. Indeed, both phylogenies and taxonomies are semi-labeled trees [5, 18]. We
will use this term throughout the rest of the paper to refer to trees with nested taxa.
The fastest previous algorithm for testing ancestral compatibility, based on earlierwork by Daniel and
Semple [7], is due to Berry and Semple [3]. Their algorithm runs in O log2 n · τP time using O (τP )
P P
space. Here, n is the number of distinct taxa in P and τP = ki=1 v∈I(Ti ) d(v)2 , where I(Ti ) is the set
of internal nodes of Ti , for each i ∈ {1, . . . , k}, and d(v) is the degree of node v. While the algorithm is
polynomial, its dependence on node degrees is problematic: semi-labeled trees can be highly unresolved
(i.e., contain nodes of high degree), especially if they are taxonomies.
Our contributions. The Õ(MP ) running time of our ancestral compatibility algorithm is independent of
the degrees of the nodes of the input trees, a valuable characteristic for large datasets that include taxonomies.
To achieve this time bound, we extend ideas from our recent algorithm for testing the compatibility of
ordinary phylogenetic trees [8]. As in that algorithm, a central notion in the current paper is the display
graph of profile P, denoted HP . This is the graph obtained from the disjoint union of the trees in P by
identifying nodes that have the same label (see Section 4). The term “display graph” was introduced by
Bryant and Lagergren [6], but similar ideas have been used elsewhere. In particular, the display graph is
closely related to Berry and Semple’s restricted descendancy graph [3], a mixed graph whose directed edges
correspond to the (undirected) edges of HP and whose undirected edges have no correspondence in HP .
The second kind of edges are the major component of the τP term in the time and space complexity of Berry
and Semple’s algorithm. The absence of such edges makes HP significantly smaller than the restricted
descendancy graph. Display graphs also bear some relation to tree alignment graphs [19].
Here, we exploit the display graph more extensively and more directly than our previous work. Although
the display graph of a collection of semi-labeled trees is more complex than that of a collection of ordinary
phylogenies, we are able to extend several of the key ideas — notably, that of a semi-universal label —
to the general setting of semi-labeled trees. As in [8], the implementation relies on a dynamic graph data
structure, but it requires a more careful amortized analysis based on a weighing scheme.
Contents. Section 2 presents basic definitions regarding semi-labeled trees and ancestral compatibility. .
Section 3 introduces the display graph and discusses its properties. Section 4 presents BuildNT, our algorithm for testing ancestral compatibility. Section 5 gives the implementation details for BuildNT. Section 6
gives some concluding remarks.

2

Preliminaries

For each positive integer r, [r] denotes the set {1, . . . , r}.
2

Let G be a graph. V (G) and E(G) denote the node and edge sets of G. The degree of a node v ∈ V (G)
is the number of edges incident on v. A tree is an acyclic connected graph. In this paper, all trees are
assumed to be rooted. For a tree T , r(T ) denotes the root of T . Suppose u, v ∈ V (T ). Then, u is an
ancestor of v in T , denoted u ≤T v, if u lies on the path from v to r(T ) in T . If u ≤T v, then v is a
descendant of u. Node u is a proper descendant of v if u is a descendant of v and v 6= u. If {u, v} ∈ E(T )
and u ≤T v, then u is the parent of v and v is a child of u. If neither u ≤T v nor v ≤T u hold, then we
write u kT v and say that u and v are not comparable in T .
Semi-labeled trees. A semi-labeled tree is a pair T = (T, φ) where T is a tree and φ is a mapping from
a set L(T ) to V (T ) such that, for every node v ∈ V (T ) of degree at most two, v ∈ φ(L(T )). L(T ) is the
label set of T and φ is the labeling function of T .
For every node v ∈ V (T ), φ−1 (v) denotes the (possibly empty) subset of L(T ) whose elements map
into v; these elements as the labels of v (thus, each label is a taxon). If φ−1 (v) 6= ∅, then v is labeled;
otherwise, v is unlabeled. Note that, by definition, every leaf in a semi-labeled tree is labeled. Further, any
node, including the root, that has a single child must be labeled. Nodes with two or more children may be
labeled or unlabeled. A semi-labeled tree T = (T, φ) is singularly labeled if every node in T has at most
one label; T is fully labeled if every node in T is labeled.
Semi-labeled trees, also known as X-trees, generalize ordinary phylogenetic trees, also known as phylogenetic X-trees [18]. An ordinary phylogenetic tree is a semi-labeled tree T = (T, φ) where r(T ) has
degree at least two and φ is a bijection from L(T ) into leaf set of T (thus, internal nodes are not labeled).
Let T = (T, φ) be a semi-labeled tree and let ` and `0 be two labels in L(T ). If φ(`) ≤T φ(`0 ), then we
write ` ≤T `0 , and say that `0 is a descendant of ` in T and that ` is an ancestor of `0 . We write ` <T `0 if
φ(`0 ) is a proper descendant of φ(`). If φ(`) kT φ(`0 ), then we write ` kT `0 and say that ` and `0 are not
comparable in T . If T is fully labeled and φ(`) is the parent of φ(`0 ) in T , then ` is the parent of `0 in T
and `0 is a child of ` in T ; two labels with the same parent are siblings.
Two semi-labelled trees T = (T, φ) and T 0 = (T 0 , φ0 ) are isomorphic if there exists a bijection ψ :
V (T ) → V (T 0 ) such that φ0 = ψ ◦ φ and, for any two nodes u, v ∈ V (T ), (u, v) ∈ E(T ) if and only
(ψ(u), ψ(v)) ∈ E(T 0 ).
Let T = (T, φ) be a semi-labeled tree.SFor each u ∈ V (T ), X(u) denotes the set of all labels in the
subtree of T rooted at u; that is, X(u) = v:u≤T v φ−1 (v). X(u) is called a cluster of T . Cl(T ) denotes
the set of all clusters of T . It is well known [18, Theorem 3.5.2] that a semi-labeled tree T is completely
determined by Cl(T ). That is, if Cl(T ) = Cl(T 0 ) for some other semi-labeled tree T 0 , then T is isomorphic
to T 0 .
Suppose A ⊆ L(T ) for a semi-labeled tree T = (T, φ). The restriction of T to A, denoted T |A, is the
semi-labeled tree whose cluster set is Cl(T |A) = {X ∩ A : X ∈ Cl(T ) and X ∩ A 6= ∅}. Intuitively, T |A
is obtained from the minimal rooted subtree of T that connects the nodes in φ(A) by suppressing all vertices
of degree two that are not in φ(A).
Let T = (T, φ) and T 0 = (T 0 , φ0 ) be semi-labeled trees such that L(T 0 ) ⊆ L(T ). T ancestrally
displays T 0 if Cl(T 0 ) ⊆ Cl(T |L(T 0 )). Equivalently, T ancestrally displays T 0 if T 0 can be obtained from
T |L(T 0 ) by contracting edges, and, for any `1 , `2 ∈ L(T 0 ), (i) if `1 <T 0 `2 , then `1 <T `2 , and (ii)
if `1 kT 0 `2 , then `1 kT `2 . The notion of “ancestrally displays” for semi-labeled trees generalizes the
well-known notion of “displays” for ordinary phylogenetic trees [18].
For a semi-labelled tree T , let
D(T ) = {(`, `0 ) : `, `0 ∈ L(T ) and ` <T `0 }

and

N (T ) = {{`, `0 } : `, `0 ∈ L(T ) and ` kT `0 }. (1)

Note that D(T ) consists of ordered pairs, while N (T ) consists of unordered pairs.
3

1,2

1

2

3
a
b

g
c

d

e

f

g
f

a

e

h

i

g

4
b

g

3

a,4
c

d

Figure 1: A profile P = {T1 , T2 , T3 } — trees are
3
ordered left-to-right. The letters are the original
a
labels; grey numbers are labels added to make the
trees fully labeled. (Adapted from [3].) b c d

b
1

d

e

h

b

i

Figure 2: A 2tree T
that ancestrally displays
g
f
the profile of Figure 1. 4
e(Adapted
f
b
afrome [3].)
h i

2

3

a

4

f
c

1

TP

c

d

f

e
h

i

g

Figure 3: The display
graph HP for the profile
ofc Figure
1.
d

Lemma 1 (Bordewich et al. [5]). Let T and T 0 be semi-labelled trees such that L(T 0 ) ⊆ L(T ). Then T
ancestrally displays T 0 if and only if D(T 0 ) ⊆ D(T ) and N (T 0 ) ⊆ N (T ).
Profiles and ancestral compatibility. Throughout the rest of this paper P = {T1 , . . . , Tk } denotes a set
where, S
for each i ∈ [k], Ti = (Ti , φi ) is a semi-labeled tree. We refer to P as a profile, and write L(P) to
denote i∈[k] L(T
S i ), the label set of P. Figure
S 1 shows a profile where L(P) = {a, b, c, d, e, f, g, h, i}. We
write V (P) for i∈[k] V (Ti ) and E(P) for i∈[k] E(Ti ), The size of P is MP = |V (P)| + |E(P)|.
P is ancestrally compatible if there is a rooted semi-labeled tree T that ancestrally displays each of the
trees in P. If T exists, we say that T ancestrally displays P (see Figure 2).
Given a subset X of L(P), the restriction of P to X, denoted P|X, is the profile {T1 |X∩L(T1 ), . . . , Tk |X∩
L(Tk )}. The proof of the following lemma is straightforward.
Lemma 2. Suppose P is ancestrally compatible and let T be a tree that ancestrally displays P. Then, for
any X ⊆ L(P), T |X ancestrally displays P|X.
A semi-labeled tree T = (T, φ) is fully labeled if every node in T is labeled. Suppose P contains trees
that are not fully labeled. We can convert P into an equivalent profile P 0 of fully-labeled
P trees as follows.
0
0
For each i ∈ [k], let li be the number of unlabeled nodes in Ti . Create a set L of n = i∈[k] li labels such
−1
that L0 ∩ L(P) = ∅. For each i ∈ [k] and each v ∈ V (Ti ) such that φ−1
i (v) = ∅, make φi (v) = {`},
0
0
where ` is a distinct element from L . We refer to P as the profile obtained by adding distinct new labels to
P (see Figure 1).
Lemma 3 (Daniel and Semple [7]). Let P 0 be the profile obtained by adding distinct new labels to P. Then,
P is ancestrally compatible if and only if P 0 is ancestrally compatible. Further, if T is a semi-labeled
phylogenetic tree that ancestrally displays P 0 , then T ancestrally displays P.
From this point forward, we shall assume that, for each i ∈ [k], Ti is fully and singularly labeled. By
Lemma 3, no generality is lost in assuming that all trees in P are fully labeled. The assumption that the trees
are singularly labeled is inessential; it is only for clarity. Note that, even with the latter assumption, a tree
that ancestrally displays P is not necessarily singularly labeled. Figure 2 illustrates this fact.

3

The Display Graph

The display graph of a profile P, denoted HP , is the graph obtained from the disjoint union of the underlying
trees T1 , . . . , Tk by identifying nodes that have the same label. Multiple edges between the same pair of
nodes are replaced by a single edge. See Figure 3.
4

HP has O(MP ) nodes and edges, and can be constructed in O(MP ) time. By our assumption that all
the trees in P are fully and singularly labeled, there is a bijection between the labels in L(P) and the nodes
of HP . Thus, from this point forward, we refer to the nodes of HP by their labels. It is easy to see that if HP
is not connected, then P decomposes into label-disjoint sub-profiles, and that P is compatible if and only if
each sub-profile is compatible. Thus, we shall assume, without loss of generality, that HP is connected.
Positions. A position (for P) is a vector U = (U (1), . . . , U (k)), where U (i) ⊆ L(Ti ), for each i ∈ [k].
Since labels may be shared among trees, we may have U (i) ∩ U (j) 6= ∅, for i, j ∈
S [k] with i 6= j. For each
i ∈ [k], let Desci (U ) = {` : `0 ≤Ti `, for some `0 ∈ U (i)}, and let DescP (U ) = i∈[k] Desci (U ).
A position U is valid if, for each i ∈ [k],
(V1) if |U (i)| ≥ 2, then the elements of U (i) are siblings in Ti and
(V2) Desci (U ) = DescP (U ) ∩ L(Ti ).
Lemma 4. For any valid position U , P|DescP (U ) = {T1 |Desc1 (U ), . . . , Tk |Desck (U )}.
Proof. By (V2), we have that Ti |Desci (U ) and Ti |DescP (U ) ∩ L(Ti ) are isomorphic, for each i ∈ [k]. The
lemma then follows from the definition of P|DescP (U ).
For any valid position U , HP (U ) denotes the subgraph of HP induced by DescP (U ).
Observation 1. For any valid position U , HP (U ) is the subgraph of HP obtained by deleting all labels in
V (HP ) \ DescP (U ), along with all incident edges.
A valid position of special interest to us is Uroot , where Uroot (i) = φ−1
i (r(Ti )), for each i ∈ [k]. That is,
Uroot (i) is a singleton containing only the label of r(Ti ). Thus, in Figure 3, (Uroot (1), Uroot (2), Uroot (3)) =
({1}, {2}, {g}). It is straightforward to verify that Uroot is indeed valid, that DescP (Uroot ) = L(P), and
that HP (Uroot ) = HP .
Semi-universal labels. Let U be a valid position, and let ` be a label in U . Then, ` is semi-universal in U
if U (i) = {`}, for every i ∈ [k] such that ` ∈ L(Ti ). It can be verified that in Figure 3, labels 1 and 2 are
semi-universal in Uroot , but g is not, since g is in both L(T2 ) and L(T3 ), but Uroot (2) 6= {g}.
The term “semi-universal”, borrowed from Pe’er et al. [14], derives from the following fact. Suppose
that P is ancestrally compatible, that T is a tree that ancestrally displays P, and that ` is a semi-universal
label for some valid position U . Then, as we shall see, ` must label the root u` of a subtree of T that
contains all the descendants of ` in Ti , for every i such that ` ∈ L(Ti ). The qualifier “semi” is because this
subtree may also contain labels that do not descend from ` in any input tree, but descend from some other
semi-universal label `0 in U instead. In this case, `0 also labels u` . This property of semi-universal labels is
exploited in both our ancestral compatibility algorithm and its proof of correctness (see Section 4).
For each label ` ∈ L(P), let k` denote the number of input trees that contain label `. We can obtain k`
for every ` ∈ L(P) in O(MP ) time during the construction of HP .
Lemma 5. Let U = (U (1), . . . , U (k)) be a valid position. Then, label ` is semi-universal in U if the
cardinality of the set J` = {i ∈ [k] : U (i) = {`}} equals k` .
Proof. By definition, U (i) = {`}, for every i ∈ J` . Since |J` | = k` , the lemma follows.

5

Successor positions. For every i ∈ [k] and every
S ` ∈ L(Ti ), let Chi (`) denote the set of children of ` in
L(Ti ). For a subset A of L(Ti ), let Chi (A) = `∈A Chi (`). Let U be a valid position, and S be the set of
semi-universal labels in U . The successor of U with respect to S is the position U 0 defined as follows. For
each ` ∈ S and each i ∈ [k], if U (i) = {`}, then U 0 (i) = Chi (`); otherwise, U 0 (i) = U (i).
In Figure 3, the set of semi-universal labels in Uroot is S = {1, 2}. Since Ch1 (1) = {3, f } and
Ch2 (2) = {e, f, g}, the successor of Uroot is U 0 = ({3, f }, {e, f, g}, {g}).
Observation 2. Let U be a valid position, and let U 0 be the successor of U with respect to the set S of
semi-universal labels in U . Then, HP (U 0 ) can be obtained from HP (U ) by doing the following for each
` ∈ S: (1) for each i ∈ [k] such that U (i) = {`}, delete all edges between ` and Chi (`); (2) delete `.
Let U be a valid position, and W be a subset of DescP (U ). Then, U |W denotes the position (U (1) ∩
W, . . . , U (k) ∩ W ). In Figure 3, the components of HP (U 0 ), where U 0 is the successor of Uroot , are W1 =
{3, 4, a, b, c, d, e, g} and W2 = {f, h, i}. Thus, U 0 |W1 = ({3}, {e, g}, {g}) and U 0 |W2 = ({f }, {f }, ∅).
We have the following result.
Lemma 6. Let U be a valid position, and S be the set of all semi-universal labels in U . Let U 0 be the
successor of U with respect to S, and let W1 , W2 , . . . , Wp be the label sets of the connected components of
HP (U 0 ). Then, U 0 |Wj is a valid position, for each j ∈ [p].
Proof. It suffices to argue that U 0 satisfies conditions (V1) and (V2). The lemma then follows from the fact
that the connected components of HP (U 0 ) are label-disjoint.
U 0 must satisfy condition (V1), since U does. Suppose ` ∈ S. Then, for each i ∈ [k] such that ` ∈ L(Ti ),
Desci (U 0 ) = Desci (U ) \ {`} and DescP (U 0 ) ∩ L(Ti ) = (DescP (U ) ∩ L(Ti )) \ {`}. Thus, since (V2) holds
for U , it also holds for U 0 .

4

Testing Ancestral Compatibility

BuildNT (Algorithm 1) is our algorithm for testing compatibility of semi-labeled trees. Its argument, U , is a
valid position in P such that HP (U ) is connected. Line 1 computes the set S of semi-universal labels in U .
If S is empty, then, as argued in Theorem 1 below, P|DescP (U ) is incompatible, and, thus, so is P. This
fact is reported in Line 3. Line 4 checks if S contains exactly one label `, with no proper descendants. If so,
by the connectivity assumption, ` must be the only element in DescP (U ). Therefore, Line 5 simply returns
the tree with a single node, labeled `. Line 6 updates U , replacing it by its successor with respect to S.
Let W1 , . . . , Wp be the connected components of HP (U ) after updating U . By Lemma 6, U |Wj is a valid
position, for each j ∈ [p]. Lines 7–11 recursively invoke BuildNT on U |Wj for each j ∈ [p], to determine
if there is a tree tj that ancestrally displays P|DescP (U ∩ Wj ). If any subproblem is incompatible, Line
11 reports that P is incompatible. Otherwise, Lines 12–13 assemble the tj s into a single tree that displays
P|DescP (U ), whose root is labeled by the semi-universal labels in the set S of Line 1.
Next, we argue the correctness of BuildNT.
Theorem 1. Let P = {T1 , . . . , Tk } be a profile and let Uroot = (Uroot (1), . . . , Uroot (k)), where, for each
i ∈ [k], Uroot (i) = φ−1
i (r(Ti )). Then, BuildNT(Uroot ) returns either (i) a semi-labeled tree T that ancestrally displays P, if P is ancestrally compatible, or (ii) incompatible otherwise.
Proof. (i) Suppose that BuildNT(Uroot ) outputs a semi-labeled tree T . We prove that T ancestrally displays
P. By Lemma 1, it suffices to show that D(Ti ) ⊆ D(T ) and N (Ti ) ⊆ N (T ), for each i ∈ [k].
6

Algorithm 1: BuildNT(U )
Input: A valid position U for P such that HP (U ) is connected.
Output: A semi-labeled tree that ancestrally displays P 0 = P|DescP (U ), if P 0 is ancestrally
compatible; incompatible otherwise.
1 Let S = {` ∈ U : ` is semi-universal in U }
2 if S = ∅ then
3
return incompatible
4 if |S| = 1 and the single element, `, of S has no proper descendants then
5
return the tree consisting of exactly one node, whose label set is {`}
6 Replace U by the successor of U with respect to S.
7 Let W1 , W2 , . . . , Wp be the connected components of HP (U )
8 foreach j ∈ [p] do
9
Let tj = BuildNT(U |Wj )
10
if tj is not a tree then
11
return incompatible
12 Create a node rU , whose label set is S
13 return the tree with root rU and subtrees t1 , . . . , tp

Consider any (`, `0 ) ∈ D(Ti ). Then, ` has a child `00 in Ti such that `00 ≤Ti `0 . There must be a recursive
call to BuildNT(U ), for some valid position U , where ` is the set S of semi-universal labels obtained in
Line 1. By Observation 2, label `00 , and thus `0 , both lie in one of the connected components of the graph
obtained by deleting all labels in S, including `, and their incident edges from HP (U ). It now follows from
the construction of T that (`, `0 ) ∈ D(T ). Thus, D(Ti ) ⊆ D(T ).
Now, consider any {`, `0 } ∈ N (Ti ). Let v be the lowest common ancestor of φi (`) and φi (`0 ) in Ti and
let `v be the label of v. Then, `v has a pair of children, `1 and `2 say, in Ti such that `1 ≤Ti `, and `2 ≤Ti `0 .
Because BuildNT(Uroot ) returns a tree, there are recursive calls BuildNT(U1 ) and BuildNT(U2 ) for valid
positions U1 and U2 such that `1 is semi-universal for U1 and `2 is semi-universal for U2 . We must have
U1 6= U2 ; otherwise, |U1 (i)| = |U2 (i)| ≥ 2, and, thus, neither `1 nor `2 is semi-universal, a contradiction.
Further, it follows from the construction of T that we must have DescP (U1 ) ∩ DescP (U2 ) = ∅. Hence,
` kT `0 , and, therefore, {`, `0 } ∈ N (T ).
(ii) Asssume, by way of contradiction, that BuildNT(Uroot ) returns incompatible, but that P is ancestrally compatible. By assumption, there exists a semi-labeled tree T that ancestrally displays P. Since
BuildNT(Uroot ) returns incompatible, there is a recursive call to BuildNT(U ) for some valid position U
such that U has no semi-universal label, and the set S of Line 1 is empty.
By Lemma 2, T |DescP (U ) ancestrally displays P|DescP (U ). Thus, by Lemma 4, T |DescP (U ) ancestrally displays Ti |Desci (U ), for every i ∈ [k]. Let ` be any label in the label set of the root of T |DescP (U ).
Then, for each i ∈ [k] such that ` ∈ L(Ti ), ` must be the label of the root of Ti |Desci (U ). Thus, for each
such i, U (i) = {`}. Hence, ` is semi-universal in U , a contradiction.

5

Implementation

Here we describe an efficient implementation of BuildNT. We focus on two key aspects: finding semiuniversal labels in Line 1, and updating U and HP (U ) in Lines 6 and 7.

7

By Observation 1, at each recursive call, BuildNT deals with a graph obtained from HP through edge and
node deletions. To handle these deletions efficiently, we represent HP using the dynamic graph connectivity
data structure of Holm et al. [12], which we refer to as HDT. HDT allows us to maintain the list of nodes
in each component, as well as the number of these nodes so that, if we start with no edges in a graph with
N nodes, the amortized cost of each update is O(log2 N ). Since HP has O(MP ) nodes, each update takes
O(log2 MP ) time. The total number of edge and node deletions performed by BuildNT(Uroot ) — including
all deletions in the recursive calls — is at most the total number of edges and nodes in HP , which is O(MP ).
HDT allows us to maintain connectivity information throughout the entire algorithm in O(MP log2 MP )
time.
As deletions are performed on HP , BuildNT maintains three data fields for each connected component
Y that is created: Y.weight, Y.map, and Y.semiU. It also maintains a field `.count, for each ` ∈ L(P).
P
1. Y.weight equals `∈Y k` .
2. Y.map is a map from a set JY ⊆ [k] to a set of nonempty subsets of Y ∩ L(Ti ). For each i ∈ JY ,
Y.map(i) denotes the set associated with i.
3. `.count equals the cardinality of the set {i ∈ [k] : Y.map(i) is defined and Y.map(i) = {`}}. (Recall
that k` is the number of input trees that contain `.)
4. Y.semiU is a set containing all labels ` ∈ Y such that `.count = k` .
Informally, each set Y.map(i) corresponds to a non-empty U (i); Y.semiU corresponds to the semi-universal
labels in Y . Next, we formalize these ideas.
At the start of the execution of BuildNT(U ) for any valid position U , HP (U ) has a single connected
component, YU = DescP (U ). Our implementation maintains the following invariant.
INV: At the beginning of the execution of BuildNT(U ), YU .map(i) = U (i) for each i ∈ [k] such that
U (i) 6= ∅, and YU .map(i) is undefined for each i ∈ [k] such that U (i) = ∅.
Thus, `.count equals the number of indices i ∈ [k] such that U (i) = {`}. Along with Lemma 5, INV implies that, at the beginning of the execution of BuildNT(U ), YU .semiU contains precisely the semi-universal
labels of U . Thus, the set S of line 1 of BuildNT(U ) can be retrieved in O(1) time.
To establish INV for the initial valid position Uroot , we proceed as follows. By assumption, HP (Uroot )
has a single connected component, Yroot = L(P). Since HP (Uroot
P) equals HP , we initialize data fields 1–4
for Yroot during the construction of HP . Yroot .weight is simply `∈L(P) k` . For each i ∈ [k], Yroot .map(i)
is {`}, where ` is the label of the root of Ti . We initialize the count fields as follows. First, set `.count to
0 for all ` ∈ L(P). Then, iterate through each i ∈ [k], incrementing `.count by one if Yroot .map(i) = {`}.
Finally, Yroot .semiU consists of all ` ∈ Uroot such that `.count = k` . All data fields can be initialized in
O(MP ) time.
We now focus on Lines 6 and 7 of BuildNT. By Observation 2, we can update U and HP (U ) jointly as
follows. We use a temporary variable GBNT . Prior to executing Line 6, we set GBNT = HP (U ). Then, we
successively consider each label ` ∈ S, and perform two steps: (i) initialize data fields 1–4 in preparation
for the deletion of ` and (ii) delete from GBNT the edges incident on ` and then ` itself, updating data fields
1–4 as necessary, to maintain INV. After these steps are executed, GBNT will equal HP (U ) for the new set U
created by Line 6. Steps (i) and (ii) are done by Initialize(`) (Algorithm 2) and Delete(`) (Algorithm
3), respectively.
Lines 1–5 of Initialize(`) initialize Y.map and Y.semiU to reflect the fact that label ` ∈ S is leaving
U (i), for each i ∈ [k] such that i ∈ L(Ti ), to be replaced by its children in Ti , and will no longer be
semi-universal. Lines 6–9 are needed to update certain count fields due to the possibility that singleton
sets Y.map(i) may be created in the preceding steps. The number of operations on Y.map performed by
8

P
Initialize(`) is O( i∈[k]:`∈L(Ti ) |Chi (`)|); i.e., it is proportional to the total number of children of ` in
all the input trees. Since ` is considered only once, the total number of operations on map fields of the
various sets Y considered over the entire execution of BuildNT(Uroot ) is O(MP ). The number of updates
of Y.map done by Initialize(`) is at most k` ; the total over all ` considered by BuildNT(Uroot ) over its
entire execution is O(MP ).
Algorithm 2: Initialize(`)
1
2
3
4
5
6
7
8
9

Delete ` from Y.semiU
foreach i ∈ [k] such that ` ∈ L(Ti ) do
Delete Y.map(i)
foreach α ∈ Chi (`) do
Add α to Y.map(i)
if Y.map(i) is a singleton then
Let β be the single element in Y.map(i)
Set β.count = β.count + 1
if β.count = kβ then add β to Y.semiU

Delete(`) begins by consulting HDT to identify the connected component Y that currently contains
`. The loop in Lines 2–19 successively deletes each edge between ` and a child α of `, updating the
appropriate data fields for the resulting connected components. Line 4 queries the HDT data structure to
determine whether deleting (`, α) splits Y into two components. If Y remains connected, no updates are
needed — the continue statement skips the rest of the current iteration and proceeds directly to the next.
Otherwise, Y is split into two parts Y1 and Y2 . Delete uses a weighted version of the technique of scanning
the smaller component [9]. Line 4 identifies which of the two components has the smaller weight field;
without loss of generality, it assumes that Y1 .weight ≤ Y2 .weight. Lines 5 and 6 initialize Y1 .map and
Y1 .semiU to null and Y2 .map and Y2 .semiU to the corresponding fields of Y . Lines 8–11, scan each label β
in Y1 , from Y2 .map(i) to Y1 .map(i), for every i such that β ∈ L(Ti ). Set J, updated in Line 11, keeps track
of the indices i such that Y1 .map(i) and Y2 .map(i) are modified. Lines 12–19 iterate through J to determine
if any new singleton sets were created in either Y1 or Y2 . This operation requires at most one update in each
of Y1 .semiU and Y2 .semiU; each update takes O(1) time. After all edges incident on ` are deleted, ` itself
is deleted (Line 20).
The preceding description of Delete(`) omits the updating of the weight fields of the connected components created by an edge deletion. This is done before Line 4, by (again) using the technique of scanning
the smaller component. We consult HDT to determine which of Y1 and Y2 has fewer labels. Assuming, without loss of generality, that |Y1 | < |Y2 |, compute Y1 .weight in a sequential scan of Y1 . Then,
Y2 .weight = Y.weight − Y1 .weight.
Let us track the number of operations on map fields in Lines 8–11 of Delete(`) that can be attributed to
some specific label β ∈ L(P) over the entire execution of BuildNT(Uroot ). Each execution of Lines 8–11 for
β performs kβ operations on map fields. Let wr (β) be the weight of the connected component containing
β at the beginning
of the loop of Lines 8–11, at the rth time that β is considered in those lines; thus,
P
w0 (β) ≤ `∈L(P) k` . Then, wr (β) ≤ w0 (β)/2r . The reason is that we only consider β if (i) β is contained
in one of the two components that result from deleting an edge in Line 3 and (ii) the component containing
β has the smaller weight of the two components. Thus, the number of times β is considered in Lines
8–11 over the entire execution of BuildNT(Uroot ) is O(log w0 (β)), which is O(log MP ), since
P w0 (β) =
O(MP ). Therefore, the total number of updates of map fields over all labels is O(log MP · `∈L(P) k` ),
9

Algorithm 3: Delete(`)
1
2
3
4

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

Let Y be the connected component of GBNT that contains `
foreach α ∈ Ch(`) do
Delete edge {`, α} from GBNT
if Y remains connected then continue Let Y1 , Y2 be the connected components of GBNT ; assume
that Y1 .weight ≤ Y2 .weight
Let Y1 .map = null and Y1 .semiU = null
Let Y2 .map = Y.map and Y2 .semiU = Y.semiU
Let J = ∅
foreach β ∈ Y1 do
foreach i ∈ [k] such that β ∈ L(Ti ) do
Move β from Y2 .map(i) to Y1 .map(i)
J = J ∪ {i}
foreach i ∈ J do
foreach j ∈ {1, 2} do
if Yj .map(i) = ∅ then
Delete Yj .map(i)
else if Yj .map(i) is a singleton then
Let γ be the single element in Yj .map(i)
γ.count = γ.count + 1
if γ.count = kγ then add γ to Yj .semiU
Delete ` from GBNT

which is O(MP log MP ). It can be verified that the number of updates to count and semiU fields is also
O(MP log MP ). A similar analysis shows that the total time to update weight fields over all edge deletions
performed by BuildNT(Uroot ) is O(MP log MP ).
To summarize, the work done by BuildNT(Uroot ) consists of three parts: (i) initialization, (ii) maintaining connected components, and (iii) maintaining the weight, map, and semiU, and fields for each connected
component, as well as `.count for each label `. Part (i) takes O(MP ) time. Part (ii) involves O(MP ) edge
and node deletions on the HDT data structure, at an amortized cost of O(log2 MP ) per deletion. Part (iii)
requires a total of O(MP log MP ) updates to the various fields. Using data structures that take logarithmic
time per update, leads to our main result.
Theorem 2. BuildNT can be implemented so that BuildNT(Uroot ) runs in O(MP log2 MP ) time.

6

Discussion

Like our earlier algorithm for compatibility of ordinary phylogenetic trees, the more general algorithm
presented here, BuildNT, is a polylogarithmic factor away from optimality (a trivial lower bound is Ω(MP ),
the time to read the input). BuildNT has a linear-space implementation, using the results of Thorup [22]. A
question to be investigated next is the performance of the algorithm on real data. Another important issue is
integrating our algorithm into a synthesis method that deals with incompatible profiles.

10

References
[1] A. V. Aho, Y. Sagiv, T. G. Szymanski, and J. D. Ullman. Inferring a tree from lowest common ancestors
with an application to the optimization of relational expressions. SIAM J. Comput., 10(3):405–421,
1981.
[2] B. R. Baum. Combining trees as a way of combining data sets for phylogenetic inference, and the
desirability of combining gene trees. Taxon, 41:3–10, 1992.
[3] V. Berry and C. Semple. Fast computation of supertrees for compatible phylogenies with nested taxa.
Systematic Biology, 55(2):270–288, 2006.
[4] O. R. P. Bininda-Emonds, M. Cardillo, K. E. Jones, R. D. E. MacPhee, R. M. D. Beck, R. Grenyer,
S. A. Price, R. A. Vos, J. L. Gittleman, and A. Purvis. The delayed rise of present-day mammals.
Nature, 446:507–512, 2007.
[5] M. Bordewich, G. Evans, and C. Semple. Extending the limits of supertree methods. Annals of
Combinatorics, 10:31–51, 2006.
[6] D. Bryant and J. Lagergren. Compatibility of unrooted phylogenetic trees is FPT. Theoretical Computer Science, 351:296–302, 2006.
[7] P. Daniel and C. Semple. Supertree algorithms for nested taxa. In O. R. P. Bininda-Emonds, editor,
Phylogenetic supertrees: Combining information to reveal the Tree of Life, pages 151–171. Kluwer,
Dordrecht, 2004.
[8] Y. Deng and D. Fernández-Baca. Fast compatibility testing for rooted phylogenetic trees. In Proceedings of 27th Annual Symposium on Combinatorial Pattern Matching, to appear.
[9] S. Even and Y. Shiloach. An on-line edge-deletion problem. J. ACM, 28(1):1–4, Jan. 1981.
[10] M. R. Henzinger, V. King, and T. Warnow. Constructing a tree from homeomorphic subtrees, with
applications to computational evolutionary biology. Algorithmica, 24:1–13, 1999.
[11] C. E. Hinchliff, S. A. Smith, J. F. Allman, J. G. Burleigh, R. Chaudhary, L. M. Coghill, K. A. Crandall,
J. Deng, B. T. Drew, R. Gazis, K. Gude, D. S. Hibbett, L. A. Katz, H. D. Laughinghouse IV, E. J.
McTavish, P. E. Midford, C. L. Owen, R. H. Reed, J. A. Reesk, D. E. Soltis, T. Williams, and K. A.
Cranston. Synthesis of phylogeny and taxonomy into a comprehensive tree of life. Proceedings of the
National Academy of Sciences, 112(41):12764–12769, 2015.
[12] J. Holm, K. de Lichtenberg, and M. Thorup. Poly-logarithmic deterministic fully-dynamic algorithms
for connectivity, minimum spanning tree, 2-edge, and biconnectivity. J. ACM, 48(4):723–760, July
2001.
[13] R. M. Page. Taxonomy, supertrees, and the tree of life. In O. R. P. Bininda-Emonds, editor, Phylogenetic supertrees: Combining information to reveal the Tree of Life, pages 247–265. Kluwer, Dordrecht,
2004.
[14] I. Pe’er, T. Pupko, R. Shamir, and R. Sharan. Incomplete directed perfect phylogeny. SIAM J. Comput.,
33(3):590–607, 2004.
11

[15] M. A. Ragan. Phylogenetic inference based on matrix representation of trees. Molecular Phylogenetics
and Evolution, 1:53–58, 1992.
[16] M. J. Sanderson. Phylogenetic signal in the eukaryotic tree of life. Science, 321(5885):121–123, 2008.
[17] E. W. Sayers et al. Database resources of the National Center for Biotechnology Information. Nucleic
Acids Research, 37(Database issue):D5–D15, 2009.
[18] C. Semple and M. Steel. Phylogenetics. Oxford Lecture Series in Mathematics. Oxford University
Press, Oxford, 2003.
[19] S. A. Smith, J. W. Brown, and C. E. Hinchliff. Analyzing and synthesizing phylogenies using tree
alignment graphs. PLoS Computational Biology, 9(9):e1003223, 2013.
[20] M. A. Steel. The complexity of reconstructing trees from qualitative characters and subtrees. J.
Classification, 9:91–116, 1992.
[21] The Angiosperm Phylogeny Group. An update of the Angiosperm Phylogeny Group classification
for the orders and families of flowering plants: APG IV. Botanical Journal of the Linnean Society,
181:1–20, 2016.
[22] M. Thorup. Near-optimal fully-dynamic graph connectivity. In Proceedings of the 32nd Annual ACM
Symposium on Theory of Computing, pages 343–350. ACM, 2000.

12

