Rotation distance

Last updated

In discrete mathematics and theoretical computer science, the rotation distance between two binary trees with the same number of nodes is the minimum number of tree rotations needed to reconfigure one tree into another. Because of a combinatorial equivalence between binary trees and triangulations of convex polygons, rotation distance is equivalent to the flip distance for triangulations of convex polygons.

Contents

Rotation distance was first defined by Karel Čulík II and Derick Wood in 1982. [1] Every two n-node binary trees have rotation distance at most 2n 6, and some pairs of trees have exactly this distance. The computational complexity of computing the rotation distance is unknown. [2]

Definition

Tree rotation BinaryTreeRotations.svg
Tree rotation

A binary tree is a structure consisting of a set of nodes, one of which is designated as the root node, in which each remaining node is either the left child or right child of some other node, its parent, and in which following the parent links from any node eventually leads to the root node. (In some sources, the nodes described here are called "internal nodes", there exists another set of nodes called "external nodes", each internal node is required to have exactly two children, and each external node is required to have zero children. [1] The version described here can be obtained by removing all the external nodes from such a tree.)

For any node x in the tree, there is a subtree of the same form, rooted at x and consisting of all the nodes that can reach x by following parent links. Each binary tree has a left-to-right ordering of its nodes, its inorder traversal, obtained by recursively traversing the left subtree (the subtree at the left child of the root, if such a child exists), then listing the root itself, and then recursively traversing the right subtree. In a binary search tree, each node is associated with a search key, and the left-to-right ordering is required to be consistent with the order of the keys. [2]

A tree rotation is an operation that changes the structure of a binary tree without changing its left-to-right ordering. Several self-balancing binary search tree data structures use these rotations as a primitive operation in their rebalancing algorithms. A rotation operates on two nodes x and y, where x is the parent of y, and restructures the tree by making y be the parent of x and taking the place of x in the tree. To free up one of the child links of y and make room to link x as a child of y, this operation may also need to move one of the children of y to become a child of x. There are two variations of this operation, a right rotation in which y begins as the left child of x and x ends as the right child of y, and a left rotation in which y begins as the right child of x and x ends as the left child of y. [2]

Any two trees that have the same left-to-right sequence of nodes may be transformed into each other by a sequence of rotations. The rotation distance between the two trees is the number of rotations in the shortest possible sequence of rotations that performs this transformation. It can also be described as the shortest path distance in a rotation graph, a graph that has a vertex for each binary tree on a given left-to-right sequence of nodes and an edge for each rotation between two trees. [2] This rotation graph is exactly the graph of vertices and edges of an associahedron. [3]

Equivalence to flip distance

The flip graphs of a pentagon and a hexagon, corresponding to rotations of three-node and four-node binary trees Flip graphs.svg
The flip graphs of a pentagon and a hexagon, corresponding to rotations of three-node and four-node binary trees

Given a family of triangulations of some geometric object, a flip is an operation that transforms one triangulation to another by removing an edge between two triangles and adding the opposite diagonal to the resulting quadrilateral. The flip distance between two triangulations is the minimum number of flips needed to transform one triangulation into another. It can also be described as the shortest path distance in a flip graph , a graph that has a vertex for each triangulation and an edge for each flip between two triangulations. Flips and flip distances can be defined in this way for several different kinds of triangulations, including triangulations of sets of points in the Euclidean plane, triangulations of polygons, and triangulations of abstract manifolds.

There is a one-to-one correspondence between triangulations of a given convex polygon, with a designated root edge, and binary trees, taking triangulations of n-sided polygons into binary trees with n 2 nodes. In this correspondence, each triangle of a triangulation corresponds to a node in a binary tree. The root node is the triangle having the designated root edge as one of its sides, and two nodes are linked as parent and child in the tree when the corresponding triangles share a diagonal in the triangulation. Under this correspondence, rotations in binary trees correspond exactly to flips in the corresponding triangulations. Therefore, the rotation distance on (n 2)-node trees corresponds exactly to flip distance on triangulations of n-sided convex polygons.

Maximum value

Čulík & Wood (1982) define the "right spine" of a binary tree to be the path obtained by starting from the root and following right child links until reaching a node that has no right child. If a tree has the property that not all nodes belong to the right spine, there always exists a right rotation that increases the length of the right spine. For, in this case, there exists at least one node x on the right spine that has a left child y that is not on the right spine. Performing a right rotation on x and y adds y to the right spine without removing any other node from it. By repeatedly increasing the length of the right spine, any n-node tree can be transformed into the unique tree with the same node order in which all nodes belong to the right spine, in at most n 1 steps. Given any two trees with the same node order, one can transform one into the other by transforming the first tree into a tree with all nodes on the right spine, and then reversing the same transformation of the second tree, in a total of at most 2n 2 steps. Therefore, as Čulík & Wood (1982) proved, the rotation distance between any two trees is at most 2n 2. [1]

By considering the problem in terms of flips of convex polygons instead of rotations of trees, Sleator, Tarjan & Thurston (1988) were able to show that the rotation distance is at most 2n 6. In terms of triangulations of convex polygons, the right spine is the sequence of triangles incident to the right endpoint of the root edge, and the tree in which all vertices lie on the spine corresponds to a fan triangulation for this vertex. The main idea of their improvement is to try flipping both given triangulations to a fan triangulation for any vertex, rather than only the one for the right endpoint of the root edge. It is not possible for all of these choices to simultaneously give the worst-case distance n 1 from each starting triangulation, giving the improvement. [2]

Sleator, Tarjan & Thurston (1988) also used a geometric argument to show that, for infinitely many values of n, the maximum rotation distance is exactly 2n 6. They again use the interpretation of the problem in terms of flips of triangulations of convex polygons, and they interpret the starting and ending triangulation as the top and bottom faces of a convex polyhedron with the convex polygon itself interpreted as a Hamiltonian circuit in this polyhedron. Under this interpretation, a sequence of flips from one triangulation to the other can be translated into a collection of tetrahedra that triangulate the given three-dimensional polyhedron. They find a family of polyhedra with the property that (in three-dimensional hyperbolic geometry) the polyhedra have large volume, but all tetrahedra inside them have much smaller volume, implying that many tetrahedra are needed in any triangulation. The binary trees obtained from translating the top and bottom sets of faces of these polyhedra back into trees have high rotation distance, at least 2n 6. [2]

Subsequently, Pournin (2014) provided a proof that for all n ≥ 11, the maximum rotation distance is exactly 2n 6. Pournin's proof is combinatorial, and avoids the use of hyperbolic geometry. [3]

Computational complexity

Unsolved problem in mathematics:

What is the complexity of computing the rotation distance between two trees?

As well as defining rotation distance, Čulík & Wood (1982) asked for the computational complexity of computing the rotation distance between two given trees. The existence of short rotation sequences between any two trees implies that testing whether the rotation distance is at most k belongs to the complexity class NP, but it is not known to be NP-complete, nor is it known to be solvable in polynomial time.

The rotation distance between any two trees can be lower bounded, in the equivalent view of polygon triangulations, by the number of diagonals that need to be removed from one triangulation and replaced by other diagonals to produce the other triangulation. It can also be upper bounded by twice this number, by partitioning the problem into subproblems along any diagonals shared between both triangulations and then applying the method of Čulík & Wood (1982) to each subproblem. This method provides an approximation algorithm for the problem with an approximation ratio of two. [4] A similar approach of partitioning into subproblems along shared diagonals leads to a fixed-parameter tractable algorithm for computing the rotation distance exactly. [5] [6]

Determining the complexity of computing the rotation distance exactly without parameterization remains unsolved, and the best algorithms currently known for the problem run in exponential time. [7]

Variants

Though the complexity of rotation distance is unknown, there exists several variants for which rotation distance can be solved in polynomial time.

In abstract algebra, each element in Thompson's group F has a presentation using two generators. Finding the minimum length of such a presentation is equivalent to finding the rotation distance between two binary trees with only rotations on the root node and its right child allowed. Fordham's algorithm computes the rotation distance under this restriction in linear time. The algorithm classifies tree nodes into 7 types and uses a lookup table to find the number of rotations required to transform a node of one type into another. The sum of the costs of all transformations is the rotation distance. [8]

In two additional variants, one only allows rotations such that the pivot of the rotation is a non-leaf child of the root and the other child of the root is a leaf, while the other only allow rotations on right-arm nodes (nodes that are on the path from the root to its rightmost leaf). Both variants result in a meet semi-lattice, whose structure is exploited to derive a algorithm. [9] [10]

Related Research Articles

<span class="mw-page-title-main">AVL tree</span> Self-balancing binary search tree

In computer science, an AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is done to restore this property. Lookup, insertion, and deletion all take O(log n) time in both the average and worst cases, where is the number of nodes in the tree prior to the operation. Insertions and deletions may require the tree to be rebalanced by one or more tree rotations.

<span class="mw-page-title-main">Binary tree</span> Limited form of tree data structure

In computer science, a binary tree is a tree data structure in which each node has at most two children, referred to as the left child and the right child. That is, it is a k-ary tree with k = 2. A recursive definition using set theory is that a binary tree is a tuple (L, S, R), where L and R are binary trees or the empty set and S is a singleton set containing the root.

In computer science, a red–black tree is a specialised binary search tree data structure noted for fast storage and retrieval of ordered information, and a guarantee that operations will complete within a known time. Compared to other self-balancing binary search trees, the nodes in a red-black tree hold an extra bit called "color" representing "red" and "black" which is used when re-organising the tree to ensure that it is always approximately balanced.

<span class="mw-page-title-main">Tree (data structure)</span> Abstract data type simulating a hierarchical tree structure and represented as a set of linked nodes

In computer science, a tree is a widely used abstract data type that represents a hierarchical tree structure with a set of connected nodes. Each node in the tree can be connected to many children, but must be connected to exactly one parent, except for the root node, which has no parent. These constraints mean there are no cycles or "loops", and also that each child can be treated like the root node of its own subtree, making recursion a useful technique for tree traversal. In contrast to linear data structures, many trees cannot be represented by relationships between neighboring nodes in a single straight line.

<span class="mw-page-title-main">Tree rotation</span> A local change in a binary tree that preserves leaf order

In discrete mathematics, tree rotation is an operation on a binary tree that changes the structure without interfering with the order of the elements. A tree rotation moves one node up in the tree and one node down. It is used to change the shape of the tree, and in particular to decrease its height by moving smaller subtrees down and larger subtrees up, resulting in improved performance of many tree operations.

<span class="mw-page-title-main">Treap</span>

In computer science, the treap and the randomized binary search tree are two closely related forms of binary search tree data structures that maintain a dynamic set of ordered keys and allow binary searches among the keys. After any sequence of insertions and deletions of keys, the shape of the tree is a random variable with the same probability distribution as a random binary tree; in particular, with high probability its height is proportional to the logarithm of the number of keys, so that each search, insertion, or deletion operation takes logarithmic time to perform.

In computer science, tree traversal is a form of graph traversal and refers to the process of visiting each node in a tree data structure, exactly once. Such traversals are classified by the order in which the nodes are visited. The following algorithms are described for a binary tree, but they may be generalized to other trees as well.

<i>k</i>-d tree Multidimensional search tree for points in k dimensional space

In computer science, a k-d tree is a space-partitioning data structure for organizing points in a k-dimensional space. K-dimensional is that which concerns exactly k orthogonal axes or a space of any number of dimensions. k-d trees are a useful data structure for several applications, such as:

In computer science, a leftist tree or leftist heap is a priority queue implemented with a variant of a binary heap. Every node x has an s-value which is the distance to the nearest leaf in subtree rooted at x. In contrast to a binary heap, a leftist tree attempts to be very unbalanced. In addition to the heap property, leftist trees are maintained so the right descendant of each node has the lower s-value.

In computer science, weight-balanced binary trees (WBTs) are a type of self-balancing binary search trees that can be used to implement dynamic sets, dictionaries (maps) and sequences. These trees were introduced by Nievergelt and Reingold in the 1970s as trees of bounded balance, or BB[α] trees. Their more common name is due to Knuth.

<span class="mw-page-title-main">Cartesian tree</span> Binary tree derived from a sequence of numbers

In computer science, a Cartesian tree is a binary tree derived from a sequence of distinct numbers. To construct the Cartesian tree, set its root to be the minimum number in the sequence, and recursively construct its left and right subtrees from the subsequences before and after this number. It is uniquely defined as a min-heap whose symmetric (in-order) traversal returns the original sequence.

<span class="mw-page-title-main">Associahedron</span> Convex polytope of parenthesizations

In mathematics, an associahedronKn is an (n – 2)-dimensional convex polytope in which each vertex corresponds to a way of correctly inserting opening and closing parentheses in a string of n letters, and the edges correspond to single application of the associativity rule. Equivalently, the vertices of an associahedron correspond to the triangulations of a regular polygon with n + 1 sides and the edges correspond to edge flips in which a single diagonal is removed from a triangulation and replaced by a different diagonal. Associahedra are also called Stasheff polytopes after the work of Jim Stasheff, who rediscovered them in the early 1960s after earlier work on them by Dov Tamari.

<span class="mw-page-title-main">Unrooted binary tree</span>

In mathematics and computer science, an unrooted binary tree is an unrooted tree in which each vertex has either one or three neighbors.

In mathematics and computer science, a stack-sortable permutation is a permutation whose elements may be sorted by an algorithm whose internal storage is limited to a single stack data structure. The stack-sortable permutations are exactly the permutations that do not contain the permutation pattern 231; they are counted by the Catalan numbers, and may be placed in bijection with many other combinatorial objects with the same counting function including Dyck paths and binary trees.

In computer science, an optimal binary search tree (Optimal BST), sometimes called a weight-balanced binary tree, is a binary search tree which provides the smallest possible search time (or expected search time) for a given sequence of accesses (or access probabilities). Optimal BSTs are generally divided into two types: static and dynamic.

<span class="mw-page-title-main">Flip graph</span> A graph that encodes local operations in mathematics

In mathematics, a flip graph is a graph whose vertices are combinatorial or geometric objects, and whose edges link two of these objects when they can be obtained from one another by an elementary operation called a flip. Flip graphs are special cases of geometric graphs.

In computer science, a weak heap is a data structure for priority queues, combining features of the binary heap and binomial heap. It can be stored in an array as an implicit binary tree like a binary heap, and has the efficiency guarantees of binomial heaps.

In discrete mathematics and theoretical computer science, reconfiguration problems are computational problems involving reachability or connectivity of state spaces.

Reverse-search algorithms are a class of algorithms for generating all objects of a given size, from certain classes of combinatorial objects. In many cases, these methods allow the objects to be generated in polynomial time per object, using only enough memory to store a constant number of objects. They work by organizing the objects to be generated into a spanning tree of their state space, and then performing a depth-first search of this tree.

In discrete mathematics and theoretical computer science, the flip distance between two triangulations of the same point set is the number of flips required to transform one triangulation into another. A flip removes an edge between two triangles in the triangulation and then adds the other diagonal in the edge's enclosing quadrilateral, forming a different triangulation of the same point set.

References

  1. 1 2 3 Čulík, Karel II; Wood, Derick (1982), "A note on some tree similarity measures", Information Processing Letters , 15 (1): 39–42, doi:10.1016/0020-0190(82)90083-7, MR   0678031
  2. 1 2 3 4 5 6 Sleator, Daniel D.; Tarjan, Robert E.; Thurston, William P. (1988), "Rotation distance, triangulations, and hyperbolic geometry", Journal of the American Mathematical Society , 1 (3): 647–681, doi: 10.1090/S0894-0347-1988-0928904-4 , JSTOR   1990951, MR   0928904
  3. 1 2 Pournin, Lionel (2014), "The diameter of associahedra", Advances in Mathematics , 259: 13–42, arXiv: 1207.6296 , doi: 10.1016/j.aim.2014.02.035 , MR   3197650
  4. Cleary, Sean; St. John, Katherine (2010), "A linear-time approximation for rotation distance", Journal of Graph Algorithms and Applications , 14 (2): 385–390, arXiv: 0903.0199 , doi: 10.7155/jgaa.00212 , MR   2740180
  5. Cleary, Sean; St. John, Katherine (2009), "Rotation distance is fixed-parameter tractable", Information Processing Letters , 109 (16): 918–922, arXiv: 0903.0197 , doi:10.1016/j.ipl.2009.04.023, MR   2541971, S2CID   125834
  6. Lucas, Joan M. (2010), "An improved kernel size for rotation distance in binary trees", Information Processing Letters , 110 (12–13): 481–484, doi:10.1016/j.ipl.2010.04.022, MR   2667389
  7. Li, Haohong; Xia, Ge (2023-11-05), "An 𝒪(3.82^k) Time FPT Algorithm for Convex Flip Distance", Discrete & Computational Geometry , Springer Science and Business Media LLC, doi:10.1007/s00454-023-00596-9, ISSN   0179-5376
  8. Fordham, Blake (2003), "Minimal Length Elements of Thompson's Group F", Geometriae Dedicata, Springer Science and Business Media LLC, 99 (1): 179–220, doi:10.1023/a:1024971818319, ISSN   0046-5755
  9. Bonnin, André; Pallo, Jean-Marcel (1992), "A shortest path metric on unlabeled binary trees", Pattern Recognition Letters, Elsevier BV, 13 (6): 411–415, doi:10.1016/0167-8655(92)90047-4, ISSN   0167-8655
  10. Pallo, Jean Marcel (2003), "Right-arm rotation distance between binary trees", Information Processing Letters, Elsevier BV, 87 (4): 173–177, doi:10.1016/s0020-0190(03)00283-7, ISSN   0020-0190