\thesection Reduction to PQ-trees
\section

Introduction Let be any intersection graph class (such as interval graphs or chordal graphs) and let and be two graphs in , sharing some vertices and the edges induced by . and are said to be simultaneously representable graphs or simultaneous graphs if there exist intersection representations and of and such that any vertex of is represented by the same object in both and . The simultaneous representation problem for class asks whether and are simultaneous graphs. For example, Figures \refFIG:intro_interval(a) and \refFIG:intro_interval(b) show two simultaneous interval graphs and their interval representations with the property that vertices common to both graphs are assigned to the same interval. Figure \refFIG:intro_interval(c) shows two interval graphs that are not simultaneous interval graphs.

Simultaneous representation problems were introduced by us in a recent paper [JL2] and have application in any situation where two related graphs should be represented consistently. A main instance is for temporal relationships, where an old graph and a new graph share some common parts. Pairs of related graphs also arise in many other situations, e.g: two social networks that share some members; overlap graphs of DNA fragments of two similar organisms, etc. Simultaneous representations are related to simultaneous planar embeddings: two graphs that share some vertices and edges (not necessarily induced) have a simultaneous geometric embedding [BCDE] if they have planar straight-line drawings in which the common vertices are represented by common points. Thus edges may cross, but only if they are in different graphs. Deciding if two graphs have a simultaneous geometric embedding is NP-Hard [BGJPSS]. In [JL2], we showed that the simultaneous representation problem can be solved efficiently for chordal, comparability and permutation graphs. We also showed that for any intersection class , the simultaneous representation problem for and is equivalent to the following problem: Do there exist edges between and so that the augmented graph belongs to class . The graph sandwich problem [GKS] is a more general augmentation problem defined for any graph class : given graphs and , is there a set of edges with so that the graph belongs to class . This problem has a wealth of applications but is NP-complete for interval graphs, comparability graphs, and permutation graphs [GKS]. The simultaneous representation problem (for class ) is the special case of the graph sandwich problem (for ) where forms a complete bipartite subgraph. A related special case where forms a clique is the problem of recognizing probe graphs: a graph with a specified independent set is a probe graph for class if there exist edges so that the augmented graph belongs to class . Probe graphs have several applications [McMWZ, GL] and have received much attention recently. The first polynomial-time algorithm for recognizing probe interval graphs was due to Johnson and Spinrad [JS]. They used a variant of PQ-trees and achieved a run-time of . Techniques from modular decomposition provided more speed up [McCS], but the most recent algorithm by McConnell and Nussbaum [McCN] reverts to PQ-trees and achieves linear time. We note that there has also been work [Ta] on a concept of simultaneous intersection called “polysemy” where two graphs are represented as intersections of sets and their complements. In this paper, we give an algorithm for solving the simultaneous representation problem for interval graphs. We use PQ-trees, which were developed by Booth and Lueker for the original linear time interval graph recognition algorithm. They used a PQ-tree to capture the orderings of the maximal cliques of the graph (see [Golumbic] for an introduction to interval graphs and PQ-trees). In the probe interval recognition problem, there is a single PQ-tree (of the graph induced by the probes) and a set of constraints imposed by the non-probes. However in our situation we have two PQ-trees, one for each graph, that we want to re-order to “match” on the common vertex set . We begin by “reducing” each PQ-tree to contain only vertices from . This results in PQ-trees that store non-maximal cliques, and our task is to modify each PQ-tree by inserting non-maximal cliques from the other tree while re-ordering the trees to make them the same. {comment} The set of leaf-orders of the PQ-tree gives the family of permutations that the PQ-tree represents. Given a PQ-tree , and a subset of the element set, the operation REDUCE() on is defined as the PQ-tree , that satisfies all the constraints of and the additional constraint that the elements of appear consecutively in any leaf-order of . If such a tree doesn’t exist then is defined to be the null tree. Booth and Lueker [BL] gave an asymptotically linear-time algorithm for REDUCE. The first polynomial-time algorithm for recognizing probe interval graphs is due to Johnson and Spinrad [JS]. Using the ideas of modular decomposition and PQ-trees, they introduce a new data-structure called MD-PQ-trees. This is a variant of the PQ-tree in which the leaves represent the end points of the intervals, instead of maximal cliques. Their algorithm runs in time. Subsequently McConnell and Spinrad [McCS] gave a faster algorithm for recognizing probe interval graphs. They use a variant of modular decomposition tree called -tree. A -tree represents all interval realizers of an interval graph. McConnell and Spinrad show how to extend the -tree to represent probe interval realizers. Very recently, McConnell and Nussbaum [McCN] gave a linear-time algorithm using just PQ-trees. Their algorithm is significantly and surprisingly simpler than the previous algorithms. Their algorithm begins with the clique matrix induced by the probes. They next add certain rows to it that capture the constraints imposed by the non-probes and reduce the problem to testing whether the new matrix has the consecutive-ones property. This can be tested in linear-time using PQ-trees.

## \thesection Reduction to PQ-trees

In this section we transform the simultaneous interval graph problem to a problem about “compatibility” of two PQ-trees arising from the two graphs. Recall that an interval graph is defined to be the intersection graph of intervals on the real line. For any point on the line, the intervals containing that point form a clique in the graph. This leads to the fundamental one-to-one correspondence between the interval representations of an interval graph and its clique orderings, defined as follows: A clique ordering of is a sequence of (possibly empty) cliques that contains all the maximal cliques of and has the property that for each vertex , the cliques in that contain appear consecutively. Note that we allow cliques to be empty. The standard interval graph recognition algorithm attempts to find a clique order of the maximal cliques of a graph by making the maximal cliques into leaves of a PQ-tree, and imposing PQ-tree constraints to ensure that the cliques containing each vertex appear consecutively. This structure is called the PQ-tree of the graph. Note that the children of a P-node may be reordered arbitrarily and the children of a Q-node may only be reversed. We consider a node with 2 children to be a Q-node. In the figures, we use a circle to denote a P-node and a rectangle to denote a Q-node. A leaf-order of a PQ-tree is the order in which its leaves are visited in an in-order traversal of the tree, after children of P and Q-nodes are re-ordered as just described. Note that ignoring non-maximal cliques is fine for recognizing interval graphs; for our purposes, however, we want to consider clique orders and PQ-trees that may include non-maximal cliques. We say that a PQ-tree whose leaves correspond to cliques of a graph is valid if for each of its leaf orderings and for each vertex , the cliques containing appear consecutively. Let be a clique ordering of interval graph and let the maximal cliques of be (appearing in positions respectively). Note that all the cliques in between and contain . We say that is the boundary clique or boundary between and . Note that may not necessarily be present in . The sequence of cliques between and that are subsets of is said to be the right tail of . The left tail of is defined analogously. Observe that the left tail of a clique forms an increasing sequence and the right tail forms a decreasing sequence (w.r.t set inclusion). Also note that all the cliques that precede are subsets of and this sequence is called the left tail of and all the cliques that succeed are subsets of and this sequence is called the right tail of . Thus any clique ordering of consists of a sequence of maximal cliques, with each maximal clique containing a (possibly empty) left and right tail of subcliques. Let and be defined to be empty sets. An insertion of clique between and (for some ) is said to be a subclique insertion if and either or . It is clear that after a subclique insertion the resulting sequence is still a clique ordering of . A clique ordering is an extension of if can be obtained from by subclique insertions. We also say that extends to . Furthermore, we say that a clique ordering is generated by a PQ-tree, if it can be obtained from a leaf order of the PQ-tree with subclique insertions. The above definitions yield the following Lemma. {lemma} A sequence of cliques is a clique ordering of if and only if can be generated from the PQ-tree of . Let and be two interval graphs sharing a vertex set (i.e. ) and its induced edges. Note that is isomorphic to . A clique ordering of is said to be an -ordering. The -restricted PQ-tree of is defined to be the tree obtained from the PQ-tree of by replacing each clique (a leaf of the PQ-tree) with the clique . Thus there is a one-to-one correspondence between the two PQ-trees, and the leaves of the -restricted PQ-tree are cliques of . Let be an -ordering. is said to be -expandable if there exists a clique ordering of such that for . Further, we say that expands to . By the definition of clique-ordering it follows that, if is -expandable then it remains -expandable after a subclique insertion (i.e. any extension of is also -expandable). We first observe the following. {lemma} The set of -expandable -orderings is same as the set of orderings that can be generated from the -restricted PQ-tree of . {proof} Let be the PQ-tree of and be the -restricted PQ-tree of . Let be a -expandable -ordering of . Then there exists a clique ordering of such that expands to . But by Lemma Document, can be generated from (from a leaf order with subclique insertions). This in turn implies that can be generated from (from the corresponding leaf order with the corresponding subclique insertions). Now for the other direction, let be any leaf order of . Then there exists a corresponding leaf order of such that for . This implies that is a -expandable -ordering. Finally, observe that if is generated from by subclique insertions than is also a -expandable -ordering. Thus the Lemma holds. Two -orderings and are said to be compatible if both and (separately) extend to a common -ordering . For e.g. the ordering is compatible with the ordering , as they both extend to the common ordering: . Note that the compatibility relation is not transitive. Two PQ-trees and are said to be compatible if there exist orderings and generated from and (respectively) such that is compatible with . The following Lemma is our main tool. {lemma} and are simultaneous interval graphs if and only if the -restricted PQ-tree of is compatible with the -restricted PQ-tree of . {proof} By Lemma Document, it is enough to show that and are simultaneous interval graphs if and only if there exists a -expandable -ordering and a -expandable -ordering such that is compatible with . We now show this claim. Let and be as defined in the hypothesis. Since and are compatible, they can be extended to a common -ordering . Let expand to clique orderings and in and respectively. Since each vertex of appears in the same positions in both and , it is possible to obtain interval representations and of and (from and respectively) such that each vertex in has the same end points in both and . This implies that and are simultaneous interval graphs. For the other direction, let and be simultaneous interval graphs. Then there exists an augmenting set of edges such that is an interval graph. Let be a clique-ordering of . For each and , by restricting to (i.e. replacing with ), we obtain a clique ordering of . Now for , let be the -ordering obtained from by restricting each clique in to . It follows that is a -expandable -ordering and is a -expandable -ordering. Further and hence and are compatible. Our algorithm will decide if the -restricted PQ-tree of is compatible with the -restricted PQ-tree of . We first show how the -restricted PQ-trees can be simplified in several ways. Two -orderings and are said to be equivalent if for any -ordering , and are compatible if and only if and are compatible. Note that this is an equivalence relation. The Lemma below follows directly from the definitions of equivalent orderings and subclique insertions. {lemma} Let be an -ordering in which for some . Let be the -ordering obtained from by deleting . Then is equivalent to . Further, because equivalence is transitive, Lemma Document implies that an -ordering is equivalent to the -ordering in which all consecutive duplicates are eliminated. This allows us to simplify the -restricted PQ-tree of . Let be the -restricted PQ-tree of . We obtain a PQ-tree from as follows.
1. Initialize .
2. As long as there is a non-leaf node in such that all the descendants of are the same, i.e. they are all duplicates of a single clique , replace and the subtree rooted at by a leaf node representing .
3. As long as there is a (non-leaf) Q-node in with two consecutive child nodes and (among others) such that all the descendants of and are the same i.e. they are all duplicates of a single clique , replace , and the subtrees rooted at these vertices by a single leaf node representing the clique .
Note that the resulting is unique. We call the -reduced PQ-tree of . {lemma} and are simultaneous interval graphs if and only if the -reduced PQ-tree of is compatible with the -reduced PQ-tree of . {proof} For , let and be the -restricted and -reduced PQ-trees of respectively. Let be any -ordering. Observe that by Lemma Document, is compatible with a leaf ordering of if and only if is compatible with a leaf ordering of . Thus the conclusion follows from Lemma Document.

## \thesection Labeling and Further Simplification

In section 2, we transformed the simultaneous interval graph problem to a problem of testing compatibility of two -reduced PQ-trees where is the common vertex set of the two graphs. These PQ-trees may have nodes that correspond to non-maximal cliques in . In this section we prove some basic properties of such -reduced PQ-trees, and use them to further simplify each tree. Let be the -reduced PQ-tree of . Recall that each leaf of corresponds to a clique in . If is maximal in , then is said to be a max-clique and is said to be a max-clique node, otherwise is said to be a subclique and is said to be a subclique node. When the association is clear from the context, we will sometimes refer to a leaf and its corresponding clique interchangeably, or interchange the terms “max-clique” and “max-clique node” [resp. subclique and subclique node]. A node of is said to be an essential node if it is a non-leaf node or if it is a leaf node representing a max-clique. Given a node of , the descendant cliques of are the set of cliques that correspond to the leaf-descendants of . Because our algorithm operates by inserting subcliques from one tree into the other, we must take care to preserve the validity of a PQ-tree. For this we need to re-structure the tree when we do subclique insertions. The required restructuring will be determined based on the label that we assign to each node as follows.
or the Universal set of is defined as the set of vertices such that appears in all descendant cliques of .
Note that for a leaf node representing a clique , by definition. Also note that along any path up the tree, the universal sets decrease. The following Lemma gives some useful properties of the -reduced PQ-tree. {lemma} Let be the -reduced PQ-tree of . Let be a non-leaf node of ( is used in properties 2–6). Then we have:
0. Let and be two distinct leaf nodes of , containing a vertex . Let be the least common ancestor of and . Then: (a) If is a P-node then all of its descendant cliques contain . (b) If is a Q-node then is contained in all the descendant cliques of all children of between (and including) the child of that is the ancestor of and the child that is the ancestor of .
1. Each max-clique is represented by a unique node of .
2. A vertex is in if and only if for every child of , .
3. contains a max-clique as a descendant.
4. If is a P-node, then for any two child nodes and of , we have .
5. If is a P-node, then any child of that is a subclique node represents the clique .
6. If is a Q-node and and are the first and last child nodes of then . {proof} (0) Observe that in any leaf ordering of , all the nodes that appear between and must also contain the vertex , otherwise would be invalid. Now let be a leaf descendant of , that doesn’t contain . If is a P-node, then we can reorder the children of in such a way that in the leaf-ordering of the resulting tree appears between and . But this contradicts the validity of . This proves (a). Similarly, if is a Q-node, then cannot be equal to or or any node between them. Thus (b) also holds.
(1) Note that by definition of -reduced PQ-tree of , each max-clique must be present in . Now assume for the sake of contradiction that a max-clique is represented by two leaf nodes, say and . Let be the least common ancestor of and . Let and be the child nodes of that contain and (respectively) as descendants. Now by (0), if is a P-node then all of its descendant cliques must contain all the vertices of . But as is maximal, all these cliques must be precisely . However this is not possible, as we would have replaced with a leaf node representing in the construction of . Similarly, if is a Q-node then the descendant cliques of , and all the nodes between them must represent the max-clique . But then we would have replaced these nodes with with a leaf node representing in the construction of . This proves (1).
(2) If , then all the descendant cliques of contain . This implies that for any child of , all the descendant cliques of contain . Hence . On the other hand, if each child of contains a vertex in its universal set, then is present in all the descendant cliques of and thus .
(3) Note that if each descendant clique of contains precisely (and no other vertex), then we would have replaced the subtree rooted at with a leaf node corresponding to the clique , when constructing . Thus there exists a clique that is a descendant of , such that is non-empty. If is a max-clique then we are done. Otherwise let and let be a max-clique containing . Suppose is a not a descendant of . Applying (0) on and , we infer that irrespective of whether is a P-node or a Q-node, all the descendant cliques of must contain . But then , a contradiction. Thus is a descendant of .
(4) By (2) we observe that . Thus it is enough to show that . Let , then is present in all the descendant cliques of and . By (0), must be present in all the descendant cliques of and hence . Therefore .
(5) Consider any child of . Suppose is a leaf-node and is not a max-clique. It is enough to show that represents the clique i.e. . Suppose not. Then there exists a vertex . Let be a max-clique containing . Note that the common ancestor of and is either or an ancestor of . Applying (0) on and , we infer that all the descendant cliques of must contain . But then , a contradiction.
(6) This follows from (2) and (0). Let be the -reduced PQ-tree of . Recall that an essential node is a non-leaf node or a leaf node representing a maximal clique. Equivalently (by Lemma Document.3), an essential node is a node which contains a max-clique as a descendant. The following Lemma shows that in some situations we can obtain an equivalent tree by deleting subclique child nodes of a P-node . Recall that by Lemma Document.5, such subclique nodes represent the clique . {lemma} Let be the -reduced PQ-tree of and be a P-node in . Then
1. If has at least two essential child nodes, then is equivalent to the tree , obtained from by deleting all the subclique children of .
2. If has at least two subclique child nodes, then is equivalent to the tree , obtained from by deleting all except one of the subclique children of . {proof} We give the proof of (1) below. The proof of (2) is very similar and hence omitted. Let be any -ordering. It is enough to show that there exists a leaf ordering of that is compatible with if and only if there exists a leaf ordering of that is compatible with . Let be any leaf ordering of , compatible with . Consider the ordering obtained from by deleting the cliques that correspond to the child nodes of in . Clearly is a leaf ordering of . Further can be extended to by adding copies of the cliques at appropriate positions. Thus is compatible with . Now for the other direction, let be a leaf order of , compatible with and let and extend to a common ordering . From the hypothesis, we can assume that there exist two essential child nodes and of in such that the clique descendants of , appear immediately before the clique descendants of in . Also let and be the two subsequences of containing the clique descendants of and respectively. Since and are essential nodes, and each contain at least one max-clique. Let be the last max-clique in and be the first max-clique in . By Lemma Document.0, . Since is compatible with , in each of the two orderings and , occurs after and no other max-clique appears between them. Further the same holds for (as it is an extension of ). Let be the number of subclique children of (that represent the clique ). Then obtain a leaf ordering of , from , by inserting copies of between and . Now extend to by inserting copies of between and (there is a unique way of adding a subclique between two max-cliques). It is clear that is an extension of both and . Therefore is compatible with . This proves (1). We will simplify as much as possible by applying Lemma Document and by converting nodes with two children into Q-nodes. We call the end result a simplified -reduced PQ-tree, but continue to use the term “-reduced PQ-tree” to refer to it. Note that the simplification process does not change the universal sets and preserves the validity of the PQ-tree so Lemma Document and all the properties given in Lemma Document still hold. Because we consider nodes with 2 children as Q-nodes Lemma Document implies: {cor} In a [simplified] -reduced PQ-tree, any P-node has at least 3 children, and all the children are essential nodes. {comment} {proof} A P-node has at least 3 children, otherwise it would have been converted to a Q-node. By Lemma Document.2 at most one child can be a subclique node. But then at last two children are essential, so by Lemma Document.1 there are no subclique children.

## \thesection Algorithm

For , let be the [simplified] -reduced PQ-tree of . By Lemma Document, testing whether and are simultaneous interval graphs is equivalent to testing whether and are compatible. We test this by modifying and (e.g. inserting the sub-clique nodes from one tree into the other) so as to make them identical, without losing their compatibility. The following is a high level overview of our approach for checking whether and are compatible. Our algorithm is iterative and tries to match essential nodes of with essential nodes of in a bottom-up fashion. An essential node of is matched with an essential node of if and only if the subtrees rooted at and are the same i.e. their essential children are matched, their subclique children are the same and furthermore (in the case of Q-nodes) their child nodes appear in the same order. If is matched with then we consider and to be identical and use the same name (say ) to refer to either of them. Initially, we match each max-clique node of with the corresponding max-clique node of . Note that every max-clique node appears uniquely in each tree by Lemma Document.1. A sub-clique node may appear in only one tree in which case we must first insert it into the other tree. This is done when we consider the parent of the subclique node. In each iteration, we either match an unmatched node of to an unmatched node of (which may involve inserting subclique child nodes of as child nodes of and vice versa) or we reduce either or without losing their compatibility relationship. Reducing a PQ-tree means restricting it to reduce the number of leaf orderings. Finally, at the end of the algorithm either we have modified and to a “common” tree that establishes their compatibility or we conclude that is not compatible with . The common tree is said to be an intersection tree (of and ) and has the property that any ordering generated by can also be generated by and . If and are compatible, there may be several intersection trees of and , but our algorithm finds only one of them. We need the following additional notation for the rest of this paper. A sequence of subcliques is said to satisfy the subset property if for . is said to satisfy the superset property if for each . Note that satisfies the subset property if and only if satisfies the superset property. Let be an essential child node of a Q-node in . We will overload the term “tail” (previously defined for a max clique in a clique ordering) and define the tails of as follows. The left tail (resp. right tail) of is defined as the sequence of subcliques that appear as siblings of , to the immediate left (resp. right) of , such that each subclique is a subset of . Note that the left tail of should satisfy the subset property and the right tail of should satisfy the superset property (otherwise will not be valid). Also note that since the children of a Q-node can be reversed in order, “left” and “right” are relative to the child ordering of the Q-node. We will be careful to use “left tail” and “right tail” in such a way that this ambiguity does not matter. Now suppose is a matched node. Then in order to match the parent of in with the parent of in , our algorithm has to “merge” the tails of . {comment} Now let be a Q-node in with child nodes (in that order). Let , where be a (consecutive) subsequence with at least one essential node. Let be the sequence of subcliques that appear to the immediate left of (in ) such that each subclique is a subset of . Also let be the sequence of subcliques that appear to the immediate right of (in ) such that each subclique is a subset of . Note that in any ordering of there exist max-cliques and (not necessarily distinct) that are descendants of the nodes of , with the property that either is a subsequence of the left tail of and is a subsequence of the right tail of or is a subsequence of the left tail of and is a subsequence of the right tail of . Thus and satisfy the subset and superset properties respectively. Let and be two subclique sequences that satisfy the subset property. Then is said to be mergable with if the union of subcliques in and can be arranged into an ordering that satisfies the subset property. Analogously, if and satisfy the superset property, then they are said to be mergable if the union of their subcliques can be arranged into an ordering that satisfies the superset property. In both cases, is said to be the merge of and and is denoted by . A maximal matched node is a node that is matched but whose parent is not matched. For an unmatched essential node , the MM-descendants of , denoted by are its descendants that are maximal matched nodes. If is matched then we define to be the singleton set containing . Note that the MM-descendants of an essential node is non-empty (since every essential node has a max-clique descendant). Our algorithm matches nodes from the leaves up, and starts by matching the leaves that are max-cliques. As the next node that we try to match, we want an unmatched node whose essential children are already matched. To help us choose between and , and also to break ties, we prefer a node with larger set. Then, as a candidate to match to, we want an unmatched node in the other tree that has some matched children in common with . With this intuition in mind, our specific rule is as follows. Among all the unmatched essential nodes of union choose with maximal , minimal , and maximal depth, in that preference order. Assume without loss of generality that . Select an unmatched node from with maximal , minimal and maximal depth (in that order) satisfying the property that . The following Lemma captures certain properties of and , including why these rules match our intuitive justification. {lemma} For and chosen as described above, let , and . Also let and be the essential child nodes of and respectively. Then we have:
1. and .
Further when is compatible with , we have:
2. For every (matched) node in of , its corresponding matched node in is present outside the subtree rooted at . Analogously, for every (matched) node in of , its corresponding matched node in is present outside the subtree rooted at .
3. If [resp. ] is a Q-node, then in its child ordering, no node of [resp. ] can be present between two nodes of .
4. If and are Q-nodes, then in the child ordering of and , nodes of appear in the same relative order i.e. for any three nodes , appears between and in the child ordering of if and only if also appears between and in the child ordering of .
5. If (resp.) is non-empty then (resp. ). Further, if is non-empty then so is and hence .
6. Let be non-empty. If [resp. ] is a Q-node, then in its child-ordering either all nodes of [resp. ] appear before the nodes of or they all appear after the nodes of . {proof} (1) If there exists an unmatched child of , then as , and has a greater depth than , we would have chosen over . Thus every node in is matched and hence by the definition of MM-descendants . For the second part, suppose there exists a node that is not a child of . Let be the child of that contains as a descendant. must be an unmatched node. (Otherwise would have contained and not ). But then we would have picked over .
(2) Let be a (matched) node in (in ) such that the corresponding matched node in is a descendant of . Note that cannot be a child of . Otherwise and thus is in . Let be the parent of . Now cannot be a matched node. (Otherwise would have been matched to , a contradiction that is unmatched). Also is a descendant of and hence , and has greater depth than . Further is a common MM-descendant of and . This contradicts the choice of . Now let be a (matched) node in (in ), such that the corresponding matched node is a descendant of . Note that is not a child of , otherwise is a common MM-descendant of and and hence . Let be the parent of in . Since is a proper descendant of , is a matched node. Let be matched to a node in . Now is a parent of and a descendant of . But then the MM-descendants of should not have contained .
(3) Suppose in the child ordering of , node is present between nodes and . Let and be any max-cliques that are descendants of and respectively. Then in any ordering of , appears between and . But by (2), the corresponding matched node of in appears outside the subtree rooted at . Thus in any ordering of , appears either before or after both and . Thus and are not compatible. This shows the claim for . The proof for is similar.
(4) This follows from the fact that and are compatible and by observing that each matched node (in particular any node in ) contains a max-clique as a descendant.
(5) Let be a common child of and . Let be a max-clique descendant of . Suppose is non-empty. Then let be any max-clique descendant of a node in . Note that by (2), is present outside the subtree rooted at . Now by Lemma Document.0 and observing that the least common ancestor of and (in ) is an ancestor of , we get . Thus . Using an analogous argument we can show that if is non-empty then . This proves the first part of the property. For the second part we once again assume that is non-empty and hence . Now if is empty then . But this contradicts the choice of (we would have selected instead).
(6) By (5), is non-empty and . Let and suppose are any two nodes on different sides of . Let . Note that by (2), the matched nodes of in appear outside the subtree rooted at and the matched node of in appears outside the subtree rooted at . Now let and be any descendant max-cliques of and respectively. In any leaf-ordering of , appears between and , and doesn’t appear between and . But in any leaf-ordering of , either and both appear between and or they both appear before or after and . This contradicts that and are compatible. Therefore all nodes of appear before or after all nodes of in the child ordering of . Similarly, the claim also holds for the child ordering of in . We now describe the main step of the algorithm. Let and be as defined in the above Lemma. We have four cases depending on whether and are P or Q-nodes. In each of these cases, we make progress by either matching two previously unmatched essential nodes of and or by reducing and/or at or while preserving their compatibility. We show that our algorithm requires at most iterations and each iteration takes time. Thus our algorithm runs in time. During the course of the algorithm we may also insert subcliques into a Q-node when we are trying to match it to another Q-node. This is potentially dangerous as it may destroy the validity of the PQ-tree. When the Q-nodes have the same universal set, this trouble does not arise. However, in case the two Q-nodes have different universal sets, we need to re-structure the trees. Case 4, when and are both Q-nodes, has subcases to deal with these complications.

Case 1: and are both P-nodes.
By Corollary Document, the children of and are essential nodes, so and are precisely the children of and respectively. Let consist of nodes . If is empty, then by Lemma Document.5, is also empty and hence and are the same. So we match with and go to the next iteration. Suppose now that is non empty. Let . If is empty, then we use the reduction template of Figure Document to modify , matching the new parent of in to . It is easy to see that is compatible with if and only if is compatible with the modified . Now let be non-empty. In this case we use the reduction template of Figure Document to modify and to and respectively. Note that it is possible to have for some ’s, in which case the template is slightly different because we do not make a node with one child, however, the reduction always makes progress as each has at least 3 children. We now claim that is compatible with if and only if is compatible with . The reverse direction is trivial. For the forward direction, let and be two compatible leaf orderings of and respectively. Recall that by Lemma Document.2, for every [matched] node of in , the corresponding matched node in appears outside the subtree rooted at . This implies that the descendant nodes of all appear consecutively in . Hence the descendant nodes of also appear consecutively in . Thus we conclude that and are compatible if and only if the reduced trees and are also compatible. Note that both the template reductions take at most time.
{comment}

Case 2: is a P-node and is a Q-node.
If , we reduce by ordering the children of as they appear in the child ordering of , and changing into a Q-node (and leading to Case 4). This reduction preserves the compatibility of the two trees.

Now suppose . Lemma Document.5 implies that, and . By Lemma Document.6, we can assume that the nodes in appear before the nodes in in the child ordering of . Now let , and . For , let be the sequence of subcliques that appear between and in the child ordering of . Note that consists of the right tail of followed by the left tail of . We let and denote the left and right tails of and respectively. We now reduce the subtree rooted at as shown in Figure Document, changing it into a Q-node. Clearly is preserved in this operation. The correctness of this operation follows by Lemma Document.2. It is easy to see that both the template reductions run in time.
Case 3: is a Q-node and is a P-node.
If is empty, then we reduce by ordering the child nodes of (i.e. ) as they appear in the child ordering of , and changing into a Q-node. Now let be nonempty. By Lemma Document.5, . Let , and be defined as in the previous case: is the left tail of (in ), is the concatenation of the right tail of and the left tail of , for and is the right tail of . Now if is empty, then we use the template of Figure Document to reduce , grouping all nodes of into a new Q-node , ordering them in the way they appear in and inserting the subclique children of into . Note that since , this operation doesn’t change and hence it preserves the validity of . Further is identical to and hence we match these nodes. Thus we make progress even when . If is non-empty, we use the template similar to Figure Document (to reduce ) in which the roles of and have been switched. Note that the template reductions of this case run in time.

{comment}

Case 4: and are both Q-nodes
Let appear in that order in the child ordering of and . (They appear in the same order because of Lemma Document.4.) Let and be the parents of and respectively. If and have no other children than , we match with and proceed to the next iteration. More typically, they have other children. These may be essential nodes to one side or the other of (by Lemma Document.6) or subclique nodes interspersed in as tails of the nodes of . We give a high-level outline of Case 4, beginning with a discussion of subclique nodes. For , let and be the left and right tails of in and, and be the left and right tails of in . The only way to deal with the subclique nodes is to do subclique insertions in both trees to merge the tails. This is because in any intersection tree obtained from and , the tails of in must contain the merge of the tails of in and . So long as , the ordering completely determines which pairs of tails must merge: must merge with and