Better Approximation of Diagonal-Flip Transformation and Rotation Transformation (Extended Abstract) Ming Li and Louxin Zhang 1
Department of Computer Science University of Waterloo, Canada N2L 3G1
[email protected] 2 BioInformatics Center, NUS, and Kent Ridge Digital Labs, Singapore 119613
[email protected]. Abstract. Approximation algorithms are developed for the diagonalflip transformation of convex polygon triangulations and equivalently rotation transformation of binary trees. For two arbitrary triangulations in which each vertex is an end of at most d diagonals, Algorithm A has 2 . For triangulations containing the approximation ratio 2 − 4(d−1)(d+6)+1 no internal triangles, Algorithm B has the approximation ratio 1.97. Two self-interesting lower bounds on the diagonal-flip distance are also established in the analyses of these two algorithms.
1
Introduction
A rotation in a binary tree is a local restructuring of the tree that changes the position of a node and one of its children while the symmetric order in the tree is preserved. Such an operation has found its applications in many aspects. In data structures, rotations are the primitive used by most schemes that maintain “balance” in binary trees [13,18]. In graphics, morphing polygons is abstracted as rotations on weighted binary trees [6,8]. The rotation operation is also of interest from a purely mathematical point of view [11]. Further, a similar but slightly powerful operation named nearest neighbor interchange is used extensively for defining the dissimilarity between phylogenies and for heuristical search of optimal phylogenies in biology [2,17]. The rotation operation on binary trees is equivalent to the diagonal-flip operation in triangulations of a convex polygon. But, the later is more intuitive(for example, see [15]). A diagonal-flip is an operation that converts one triangulation of a polygon into another by removing a diagonal in the triangulation and adding the diagonal that subdivides the resulting quadrilateral in the opposite way. The diagonal-flip operation was early studied by Wagner [19] in the context of arbitrary triangulated planar graphs and by Dewdney [5] in the case of
Supported in part by the NSERC Operating Grant OGP0046506, ITRC and a CGAT grant. Part of the work was done at Waterloo and supported by a CGAT grant.
Wen-Lian Hsu, Ming-Yang Kao (Eds.): COCOON’98, LNCS 1449, pp. 85–94, 1998. c Springer-Verlag Berlin Heidelberg 1998
86
Ming Li and Louxin Zhang
graphs of genus one. They showed that any such graph can be transformed to any other by diagonal-flips. However, they did not try to accurately estimate how many flips are necessary. In [16], Sleator, Tarjan and Thurston proved that Ω(n log n) diagonal-flips are necessary and enough for transforming a numbered triangulated planar graph into another. In another paper [15], by using hyperbolic geometry, Sleator, Tarjan and Thurston showed beautifully that 2n − 10 diagonal flips are enough and necessary for transforming one triangulation of the n-gon into another when n is large, which improved an earlier work of Culik and Wood [3]. Since then the diagonal-flip transformation has been studied in several aspects [4,7,9]. Like [15], this paper works on diagonal-flips in triangulations rather than rotations on binary trees. It is open whether a shortest diagonal-flip transformation between two triangulations of a convex polygon is computable in polynomial time [14]. Our interest is to develop an approximation algorithm with ratio better than 2 for the diagonal-flip transformation, which is a hard problem raised in [14] and explicitly in [2] recently. Although there is a trivial approximation with ratio 2, any better approximation turns out to be very difficult. In this paper, we present an approximation algorithm that has better approximation ratio for triangulations of a convex polygon in which each vertex is an end of constantly many diagonals. We also study the diagonal-flip transformation for a special class of triangulations. In a triangulation of a convex polygon, a triangle is said to be internal if it contains three diagonals. The class of triangulation without internal triangles contains most of interesting triangulations studied in literature(for example, see [11,7]). In fact, triangulations in this class correspond one-to-one to binary trees without degree-3 nodes. For such a class of triangulations, we presents a polynomial algorithm with approximation ratio 1.97. The ratio can further be reduced by a sophisticated argument similar to our approach. However, we are not intent on giving the best possible ratio in this short abstract. The complete proofs of these results can be found in the full version of this paper. The rest of this extended abstract is divided into six sections. Section 2 introduces briefly the rotation on binary trees and the diagonal-flip in triangulations and shows the equivalence of these two operations. Section 3 gives two transformation primitives. Using Proposition 3 in this section, we are also able to answer negatively a problem posed by Knuth [11], who suspected that two specific triangulations without internal triangles has a large diagonal-flip distance. Section 4 presents a polynomial algorithm (Algorithm A) that has the approximation 2 for triangulations in which each vertex is an end of at ratio 2 − 4(d−1)(d+6)+1 most d diagonals. Section 5 presents a polynomial algorithm (Algorithm B) with approximation ratio 1.97 for triangulations without any internal triangles.
2 2.1
Definitions Binary tree rotations
A binary tree is a collection of nodes and three relations among these nodes: parent, left child and right child. A special node is called the root. Every other
Better Approximation of Diagonal-Flip Transformation
87
node has a parent and may have a left and/or right child. All nodes without any child are leaves. A binary tree has size n if it contains n nodes. (See [10] for a more complete description of binary trees and tree terminology.) A rotation is an operation that changes one binary tree into another with the same size. Figure 1 shows the general rotation rule. In a tree of size n, there are n − 1 possible rotations, each corresponding a non-root node. A rotation maintains the symmetric order of the nodes. Furthermore, a rotation is an invertible operation. We define rotation distance between two trees as the minimum number of rotations required to convert one tree into the other. The rotation distance between two binary trees of size n is at most 2n − 6 [15]. In [12], Pallo proposed a heuristic search algorithm for computing the rotation distance.
u
v rotation at u
u C A
rotation at v
B
v A
B
C
Fig. 1. The definition of rotation.
2.2
Diagonal-flips in triangulations
Binary tree rotation can be formulated with respect to different systems of combinatorial objects and their transformations. The diagonal-flip operation in triangulations is perhaps more intuitive and so supplies more insight. Consider the standard convex (n + 2)-gon. We choose an edge of the polygon as a distinguished edge, called “root edge”, and label its ends as 0 and n + 1. We also label the other n vertices from 1 to n counterclockwise. Any triangulation of the (n + 2)-gon has n triangles and n − 1 diagonals. From a triangulation of the (n + 2)-gon, we derive a binary tree of size n by assigning a node for each triangle and connecting two nodes if the corresponding triangles sharing a common diagonal. The root of the tree corresponds to the triangle containing the root edge. It is not difficult to see that the ith node of the binary tree in symmetric order corresponds to the triangle with vertices i, j and k such that j < i < k. In this way, we obtain a 1-1 correspondence between n-node binary trees and triangulations of the (n + 2)-gon as illustrated in Figure 2. A diagonal-flip is an operation that transforms one triangulation of a polygon into another as showed in Figure 3. The diagonal-flip distance between two triangulations π1 and π2 of a polygon is the minimum number of diagonal-flips needed to convert one triangulation into the other, which is denoted by f d(π1 , π2 ). Note that f d(π1 , π2 ) ≤ 2n − 10 for any two triangulations π1 and π2 of the n-gon [15].
88
Ming Li and Louxin Zhang
0
i
n 1 + |B| subgon
1 + |A| subgon A
B
i
Fig. 2. A binary tree and its corresponding triangulation.
Fig. 3. A diagonal flip in a triangulation of the hexagon.
Obviously, diagonal-flips in a triangulation correspond one-to-one to rotations in the corresponding binary tree. Other interesting relationship between a triangulation of a convex polygon and its corresponding binary tree can be found in a nice survey article [1].
3
Diagonal-flip transformation primitives
3.1
Difference Graphs
Given two triangulations π1 and π2 of the n-gon, we define their difference graph G = G(π1 , π2 ) as the union of these two triangulations. Formally, the graph G has vertex set V = {1, 2, · · · , n }, and edge set E = {1n, i(i + 1)|i = 1, 2, · · · , n − 1} ∪ Eπ1 ∪ Eπ2 , where Eπi denotes the set of n − 3 internal diagonals of πi . If an edge shared by both triangulations π1 and π2 , we call it a face edge. All the boundary edges 1n and i(i + 1), 1 ≤ i ≤ n − 1, are face edges. Since two triangulations may have common diagonals, there are other face edges in general. We define a subgraph inside a simple cycle consisting of face edges a cell. It is not difficult to see that the difference graph G can be decomposed into cells, which have disjoint diagonal edges. A difference graph G(π1 , π2 ) is simple if it has only one cell, i.e. two triangulations π1 and π2 don’t have any common diagonals. In the rest of this section, we will focus on simple difference graphs. In a difference graph, an edge is said to be a diagonal edge if it corresponds with a diagonal of one triangulation; it is a boundary edge otherwise. For a diagonal edge e ∈ E(G), let C(e) = {e ∈ E(G) | e intersects e, }, where two edges having only a common end are not considered to intersect each other. All edges in C(e) are from the other triangulation. The cardinality c(e) of C(e) is
Better Approximation of Diagonal-Flip Transformation
89
called the cross number of e. Obviously, c(e) ≥ 1 for any non-face edge e. We say a diagonal e isolated if c(e) = 1. Finally, a vertex v ∈ G(π1 , π2 ) is pure with respect to π1 (resp. π2 ) if it is only adjacent to some π1 (π2 )-diagonals; it is mixed otherwise. 3.2
Transformation primitives
Recall that f d(π1 , π2 ) denotes the diagonal-flip distance between π1 and π2 . Proposition 1. ([15]) Let π1 and π2 be two triangulations of a polygon and let e ∈ π1 be an isolated diagonal in G(π1 , π2 ). Let π2 be the triangulation created from π2 by flipping the unique edge e that intersects e. Then (1) π2 has one more common diagonal with π1 than π2 . Equivalently, the difference graph G(π1 , π2 ) has one more cell than G(π1 , π2 ); (2) f d(π1 , π2 ) = f d(π1 , π2 ) − 1. Next, we study properties relating with the degrees of vertices in difference graphs. Let π1 and π2 be two triangulations of a polygon. For a vertex v ∈ G(π1 , π2 ), the number of all diagonal edges adjacent to v is called the degree of v, denoted by d(v). By using Proposition 1, we can prove Proposition 2. Let π1 and π2 be two triangulations of a polygon and let v be a vertex such that d(v) = 1 in G(π1 , π2 ). If the unique diagonal e adjacent to v is in π1 (resp. π2 ), then flipping e creates a triangulation π1 (resp. π2 ) which has one more diagonal in common with π2 (resp. π1 ) than π1 (resp. π2 ). Proposition 3. Let π1 and π2 be two triangulations of a polygon and let u and v be two adjacent degree-2 vertices in G(π1 , π2 ). If one of u and v is pure, then it is possible to create π1 and π2 by flipping three of the four diagonals (which can be determined easily) adjacent to u or v such that (1) π1 and π2 have two more common diagonals than π1 and π2 , and (2) f d(π1 , π2 ) ≤ f d(π1 , π2 ) − 2.
4 4.1
A better approximation for arbitrary triangulations An approximation algorithm
In this section, we will present an approximation algorithm for the problem of transforming triangulations. Formally, the problem is defined as Instance: Two triangulations of a polygon; Output: A shortest diagonal-flip transformation between the given triangulations. Our approximation algorithm is described in Table 1. Obviously, the algorithm runs in polynomial time. Now we give some basic facts which will be used in analyzing its approximation ratio. Recall that G(π1 , π2 ) denotes the difference graph of π1 and π2 .
90
Ming Li and Louxin Zhang
Input: Two triangulations π1 and π2 ; Do until the following ’if’ conditions fails if there are isolated diagonals then pick such an edge e; let e be the unique diagonal that intersects e; if e ∈ π1 then π1 := π1 + e − e else π2 := π2 + e − e ; Enddo Let the resulting polygon triangulations have k cells Pi (i ≤ k), and let πj |Pi denote the restriction of πj on Pi for j = 1, 2 and i ≤ k; assume Pi has ni vertices. For each cell Pi pick a node v; transform π1 |Pi into the unique triangulation π all of whose diagonals have one end at v using at most ni steps; transform π into π2 |Pi reversely. Endfor
Table 1. Algorithm A.
Note that Algorithm A has the following properties. Proposition 4. (1) Flips in Do loop does not increase the maximum degree of the difference graph G(π1 , π2 ). (2) Flips in Do loop will not increase the number of internal triangles in G(π1 , π2 ). 4.2
Analysis of the algorithm
In this section, we shall analyze the transformation algorithm given above. Let π1 and π2 be two triangulations of the n-gon. Consider a sequence Π of diagonal-flips that transforms π1 into π2 . A diagonal-flip (ab, cd) ∈ Π is auxiliary if cd ∈ π2 . We also say flip (ab, cd) touches the vertices a, b, c, d. Let A(Π) denote the set of all auxiliary diagonal-flips in S. Then, |Π| ≥ |A(Π)| + n − 3.
(1)
Inequality 1 implies that any lower bound on the cardinality of A(Π) induces a lower bound of |Π|. In the rest of this section, we will work on |A(Π)| for a transformation sequence Π instead of its cardinality |Π|. Recall that a vertex v is pure with respect to π1 if it is only an end of π1 -diagonals. Proposition 5. Let π1 and π2 be two triangulations of a polygon and let v ∈ G(π1 , π2 ) be a pure vertex with respect to π1 . If flipping any diagonal adjacent
Better Approximation of Diagonal-Flip Transformation
91
to v does not create a π2 -diagonal, then in any sequence Π of diagonal-flips that transforms π1 into π2 , there are at least one auxiliary diagonal touching v. Proof. We consider the subpolygon consisting of v and its neighbors on boundary and adjacent nodes. Let v be adjacent to v1 , v2 , · · · , vk and let u and w be its left and right neighbors on boundary(see Figure 4). Since flipping any diagonal vvj does not create a π2 -diagonal, k ≥ 2. Since all diagonals connecting v are in π1 , uw ∈ π2 and uv1 , vi vi+1 , vk w ∈ π1 . Consider the first flip (xy, pq) touching v in the sequence Π. If pq is adjacent to v, the flip is auxiliary because all π2 -diagonals are not adjacent to v. Otherwise, we consider the diagonal adjacent to v that is first flipped away in Π . Let such an edge be vvj . For simplicity, we assume 1 < j < k. By assumption, vvj−1 and vvj+1 are π1 -diagonals. If the flip (vvj , vj−1 vj+1 ) is not auxiliary, then vj−1 vj is a π2 -diagonal and has cross number 1, contradicting to the hypothesis.
v
u
w
v1 vk
··· v2 vk−1
Fig. 4. Vertex v is an end of π1 -diagonals.
A vertex v is said to be straddle with respect to π1 if for any pair of π1 diagonals that are adjacent to v, there exists a π2 -diagonal adjacent to v between them. Otherwise, it is non-straddle. By definition, a degree-2 vertex is straddle only if it is mixed, i.e., an end of two diagonals from different triangulations. Proposition 6. Let π1 and π2 be two triangulations of a polygon such that G(π1 , π2 ) does not contain any isolated edges and let v be a non-straddle vertex with respect to π1 . If (1) v is not a vertex of any internal triangles in π1 or π2 , (2) v is not connected with any vertices of internal triangles in π2 , and (3) flipping any π1 -diagonal adjacent to v does not create a π2 -diagonal, then in any sequence Π of diagonal-flips that transforms π1 into π2 , there is at least one auxiliary diagonal touching v. Recall that a vertex v ∈ G(π1 , π2 ) is pure with respect to π1 if it is only an end of π1 -diagonals. Let V (π1 ) and V (π2 ) denote the set of pure vertices with respect to π1 and π2 respectively.
92
Ming Li and Louxin Zhang
Lemma 7. Let π1 and π2 be two triangulations of the n-gon such that G(π1 , π2 ) does not contain any isolated edges. Then, the flip distance between π1 and π2 (π2 )| is at least n − 3 + |V (π1 )|+|V . 8 Sketch of Proof. By Proposition 5, f d(π1 , π2 ) ≥ n − 3 + |V (π1 )|/4 and f d(π1 , π2 ) ≥ n − 3 + |V (π2 )|/4. Lemma 8. Let π1 and π2 be two triangulations of the n-gon in which each vertex is an end of at most d diagonals. If G(π1 , π2 ) does not contain any isolated edges, n − (d+5)(|V (π18)|+|V (π2 )|) . then f d(π1 , π2 ) ≤ n − 3 + 4(d−1) Sketch of Proof. It can be proved that a triangle with no boundary edges has at least two non-straddle vertices and a triangle with one boundary edge has at least one non-straddle vertex. Since there are exactly n − 2 − 2|V (π2 )| triangles with one boundary edge and |V (π2 )| triangles with three diagonals and the fact any vertex can be a vertex of at most (d − 1) triangles with two internal diagonals connecting it, there are at least n/(d − 1) non-straddle vertices. Since π1 and π2 have |V (π1 )| − 2 and |V (π2 )| − 2 internal triangles respectively, there are at least n/(d − 1) − 3|V (π1 )| − 3|V (π2 )| non-straddle vertices that are not in any internal triangles of π1 or π2 . Further, since each vertex is an end of n at most d π2 -diagonals, there are at least d−1 − 3|V (π1 )| − 3|V (π2 )| − (d − 1)|V (π2 )| non-traddle vertices with respect to π1 that satisfy the conditions in (π2 )| n 1 )| − 3|V (π − (d+2)|V auxiliary Proposition 6. Thus, there are at least 4(d−1) 4 4 diagonal-flips in any sequence of diagonal-flips that transforms π1 to π2 . Thus, (π2 )| n 1 )| f d(π1 , π2 ) ≥ n − 3 + 4(d−1) − 3|V (π − (d+2)|V . Similarly, f d(π1 , π2 ) ≥ 4 4 n−3+
3|V (π2 )| (π1 )| − (d+2)|V . Combining 4 4 (d+5)(|V (π1 )|+|V (π2 )|) n − 3. This 4(d−1) − 8
n 4(d−1)
−
these two bounds together,
finishes the proof. we have n + Combining Proposition 1 and 3, and Lemma 7 and 8, we have Theorem 9. On input of two triangulations π1 and π2 of the n-gon in which each vertex is an end of at most d diagonals, the transformation algorithm outputs a diagonal-flip transformation of length at most 2 )f d(π1 , π2 ). (2 − 4(d−1)(d+6)+1
5 5.1
A 1.97-approximation algorithm for triangulations without internal triangles An upper bound
First, we present an upper bound of the flip distance between π1 and π2 in term of the the number of mixed degree-2 vertices in G(π1 , π2 ). Theorem 10. Let π1 and π2 be two triangulations of the n-gon such that they do not contain any internal triangles. If G(π1 , π2 ) contains m mixed degree-2 vertices, then π1 can be transformed into π2 in at most 5(n − m) + 7m 4 flips.
Better Approximation of Diagonal-Flip Transformation
93
Input: Two triangulations π1 and π2 without internal diagonals; Do until no isolated diagonals exist in G(π1 , π2 ) pick an isolated edge e and flip the diagonal intersecting it; Enddo Let the resulting polygon triangulations have k cells Pi (i ≤ k), Let Pi have ni vertices. For each cell Pi if G(π1 |Pi , π2 |Pi ) contains more than 0.9285|Pi | mixed, degree-2 vertices, then transform π1 |Pi into πj |Pi by Thm 10; else pick a node v; transform π1 |Pi into the unique triangulation π all of whose diagonals have one end at v using at most ni steps; transform π into π2 |Pi reversely. Endfor
Table 2. Algorithm B. A 1.97-approximation algorithm for triangulations without internal triangles.
The upper bound in above theorem can be improved to 5(n − m) + 3m 2 by a more complicated technique. Here we are not intent on presenting the best possible constant. 5.2
A 1.97-approximation algorithm
Proposition 11. Let π1 and π2 be two triangulations of the n-gon that do not contain any internal triangles and let the difference graph G(π1 , π2 ) does not contain any isolated edges. If there are m mixed, degree-2 vertices in G(π1 , π2 ), then the diagonal-flip distance f d(π1 , π2 ) is at least n − 3 + n−m 8 . Our algorithm is described in Table 4.2. Obviously, it is a polynomial time algorithm. Using Proposition 11 and Theorem 10, we analyze its approximation ratio in the same way as Theorem 9. Theorem 12. On the input of two triangulations π1 and π2 of the n-gon that do not contain any internal triangles, Algorithm B outputs a diagonal-flip transformation of length at most 1.97f d(π1 , π2 ). Acknowledgment The authors would like to thank B. DasGupta, X. He, T. Jiang for useful discussions at the beginning of this work, J. Tromp for his C-code for computing rotation distances and T. Yokomori for discussions and sharing his large triangulations.
94
Ming Li and Louxin Zhang
References 1. D. Aldous, Triangulating the circle, at random. Amer Math. Monthly 89(1994), 223-234. 88 2. B. DasGupta, X. He, T. Jiang, M. Li, J. Tromp and L. Zhang, On distance between phylogenetic trees. Proc. of the SIAM-ACM 8th Annual Symposium on Discrete Algorithms, 427-436, 1997. 85, 86 3. K. Culik and D. Wood, A note on some tree similarity measures, Information Processing Letters 15(1982), 39-42. 86 4. J.-Y. Cai and M. D. Hirsch, Rotation distance, triangulation of planar surfaces and hyperbolic geometry, Proceeding of the 5th Inter. Symposium on Algorithm and Computation, Lecture Notes in Computer Science, vol. 834, 172-180, 1994. 86 5. A. K. Dewdney, Wagner’s theorem for torus graphs, Discrete Math. 4(1973), 139149. 85 6. L. Guibas and J. Hershberger, Morphing simple polygons, Proceeding of the ACM 10th Annual Sym. of Comput. Geometry, 267-276, 1994. 85 7. S. Hanke, T. Ottmann and S. Schuierer, The edge-flipping distance of triangulations. Proc. of the European Workshop of Comput. Geometry, 1996. Technical Report 76, Insttut fur Informatik, Universitat Freiburg, 1996. 86 8. J. Hershberger and S. Suri, Morphing binary trees. Proceeding of the ACM-SIAM 6th Annual Symposium of Discrete Algorithms, 396-404, 1995. 85 9. F. Hurtado, M. Noy, and J. Urrutia, Flipping edges in triangulations, Proc. of the ACM 12th Annual Sym. of Comput. Geometry, 214-223, 1996. 86 10. D. Knuth, The art of computer programming, Vol. 3: Sorting and Searching, Addison-Wesley, Reading, MA, 1973. 87 11. D. Knuth, Computer Musings (Videotape): The associative law, or the anatomy of rotations in binary trees, University Video Communications, 1993. 85, 86 12. J. Pallo, On rotation distance in the lattice of binary trees, Infor. Proc. Letters 25(1987), 369-373. 87 13. D. D. Sleator and R. Tarjan, Self-adjusting binary search trees, J. Assoc. Comput. Mach. 32(1985), 652-686. 85 14. D. D. Sleator, R. Tarjan and W. Thurston, Rotation distance, in T.M. Cover and B. Gopinath eds, Open problems in communication and computation, SpringerVerlag, 1987. 86 15. D. D. Sleator, R. Tarjan and W. Thurston, Rotation distance, triangulations, and hyperbolic geometry, Proc. of the 18th Annual ACM Symposium on Theory of Comput., Berkeley, CA., 122-135, 1986. Also appearing on J. of American Math. Soc. 1(1988), No. 3, 647 - 681. 85, 86, 87, 89 16. D. D. Sleator, R. Tarjan and W. Thurston, Short encoding of evolving structures, SIAM J. Disc. Math. 5(1992), 428-450. 86 17. D. Swofford, G. J. Olsen, P. J. Waddell and D. M. Hillis, Phylogenetic Inference, In Molecular Systematics, 2nd Edition, edited by D. M. Hillis, C. Moritz and B. K. Mable, Sinauer Associates, Mass., 1996. 85 18. R. E. Tarjan, Data structures and network algorithms, Soc. Indus. Appl. Math., Philadelphia, PA. 1983. 85 19. K. Wagner, Bemerkungen zum vierfarbenproblem, J. Deutschen Math.Verin. 46(1936), 26-32. 85