Amortized efficiency of generation, ranking and unranking left-child sequences in lexicographic order

Abstract A new type of sequences called left-child sequences (LC-sequences for short) was recently introduced by Wu et al. (2014) for representing binary trees. They pointed out that such sequences have a natural interpretation from the view point of data structure and gave a characterization of them. Based on this characterization, there is an easily implementing algorithm that uses generate-and-test approach to filter all LC-sequences of binary trees with n internal nodes in lexicographic order, while in general it is not efficient at all. In this paper, we first design two novel rotations that allow us to drastically alter the shape of binary trees (and thus their corresponding LC-sequences). As an application, these operations can be employed to generate all LC-sequences in lexicographic order. Accordingly, we present a more efficient algorithm associated with the new types of rotations for generating all LC-sequences and show that it takes only constant amortized running cost. Moreover, we extend our study to the ranking and unranking problems. By integrating a measure called “left distances” introduced by Makinen (1987) to represent binary trees, we develop efficient ranking and unranking algorithms for LC-sequences in lexicographic order. With the help of aggregate analysis, we show that both ranking and unranking algorithms can be run in amortized cost of O ( n ) time and space.

[1]  Frank Ruskey,et al.  On Rotations and the Generation of Binary Trees , 1993, J. Algorithms.

[2]  Frank Ruskey,et al.  A CAT algorithm for generating permutations with a fixed number of inversions , 2003, Inf. Process. Lett..

[3]  Jou-Ming Chang,et al.  A linear time algorithm for binary tree sequences transformation using left-arm and right-arm rotations , 2006, Theor. Comput. Sci..

[4]  A. Kensler Tree rotations for improving bounding volume hierarchies , 2008, 2008 IEEE Symposium on Interactive Ray Tracing.

[5]  Erkki Mäkinen,et al.  Left distance binary tree representations , 1987, BIT.

[6]  Shmuel Zaks,et al.  Lexicographic Generation of Ordered Trees , 1980, Theor. Comput. Sci..

[7]  Carla Savage,et al.  A Survey of Combinatorial Gray Codes , 1997, SIAM Rev..

[8]  Gonzalo Navarro,et al.  Rank and select revisited and extended , 2007, Theor. Comput. Sci..

[9]  Anthony E. Trojanowski Ranking and Listing Algorithms for k-ary Trees , 1978, SIAM J. Comput..

[10]  Ming-Tat Ko,et al.  Ranking and Unranking of Non-regular Trees in Gray-Code Order , 2013, IEICE Trans. Fundam. Electron. Commun. Comput. Sci..

[11]  Frank Ruskey,et al.  Binary Tree Gray Codes , 1985, J. Algorithms.

[12]  Dominique Roelants van Baronaigien A Loopless Algorithm for Generating Binary Tree Sequences , 1991, Inf. Process. Lett..

[13]  Jou-Ming Chang,et al.  Ranking and Unranking of t-Ary Trees Using RD-Sequences , 2011, IEICE Trans. Inf. Syst..

[14]  Kung-Jui Pai,et al.  A loopless algorithm for generating multiple binary tree sequences simultaneously , 2014, Theor. Comput. Sci..

[15]  Alan Gibbons,et al.  Rotation sequences and edge-colouring of binary tree pairs , 2004, Theor. Comput. Sci..

[16]  Alberto Del Lungo,et al.  ECO:a methodology for the enumeration of combinatorial objects , 1999 .

[17]  Jou-Ming Chang,et al.  Ranking and unranking of non-regular trees with a prescribed branching sequence , 2011, Math. Comput. Model..

[18]  Alexander Golynski Optimal lower bounds for rank and select indexes , 2007, Theor. Comput. Sci..

[19]  Joe Sawada,et al.  Generating Bracelets in Constant Amortized Time , 2001, SIAM J. Comput..

[20]  Jou-Ming Chang,et al.  Loopless Generation of Non-regular Trees with a Prescribed Branching Sequence , 2010, Comput. J..

[21]  Erkki Mäkinen,et al.  A Survey on Binary Tree Codings , 1991, Comput. J..

[22]  James F. Korsh,et al.  A loopless Gray code for rooted trees , 2006, TALG.

[23]  John M. Boyer Simple constant amortized time generation of fixed length numeric partitions , 2005, J. Algorithms.

[24]  M. C. Er Lexicographic Listing and Ranking of t-Ary Trees , 1987, Comput. J..

[25]  Jou-Ming Chang,et al.  Ranking and Unranking t-ary Trees in a Gray-Code Order , 2013, Comput. J..

[26]  Gideon Ehrlich,et al.  Loopless Algorithms for Generating Permutations, Combinations, and Other Combinatorial Configurations , 1973, JACM.

[27]  Jean Marcel Pallo,et al.  Enumerating, Ranking and Unranking Binary Trees , 1986, Comput. J..

[28]  Frank Ruskey,et al.  Generating Binary Trees Lexicographically , 1977, SIAM J. Comput..

[29]  Leonidas J. Guibas,et al.  Morphing Simple Polygons , 2000, Discret. Comput. Geom..

[30]  Shmuel Zaks,et al.  Generating Trees and Other Combinatorial Objects Lexicographically , 1979, SIAM J. Comput..

[31]  Vincent Vajnovszki,et al.  On the Loopless Generation of Binary Tree Sequences , 1998, Inf. Process. Lett..