Ranking and Unranking Algorithms for Loopless Generation of Non-regular Trees

  • Ro-Yu Wu
  • Jou-Ming Chang
  • An-Hang Chen
  • Ming-Tat Ko
Part of the Smart Innovation, Systems and Technologies book series (SIST, volume 20)


A non-regular tree T with a prescribed branching sequence (s 1,s 2,…,s n ) is an ordered tree whose internal nodes are numbered from 1 to n in preorder such that every node i in T has s i children. Recently, Wu et al. (2010) introduced a concise representation called RD-sequences to represent all non-regular trees and proposed a loopless algorithm for generating all non-regular trees in a Gray-code order. In this paper, based on such a Gray-code order, we present efficient ranking and unranking algorithms of non-regular trees with n internal nodes. Moreover, we show that each of the algorithms can be run in \({\mathcal O}(n^2)\) time provided a preprocessing takes \({\mathcal O}(n^2S_{n-1})\) time and space in advance, where \(S_{n-1}=\sum_{i=1}^{n-1}(s_i-1)\).


loopless algorithms ranking algorithm unranking algorithm lexicographic order Gray-code order non-regular trees 


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Ahmadi-Adl, A., Nowzari-Dalini, A., Ahrabian, H.: Ranking and unranking algorithms for loopless generation of t-ary trees. Logic J. IGPL 19, 33–43 (2011)MathSciNetMATHCrossRefGoogle Scholar
  2. 2.
    Ahrabian, H., Nowzari-Dalini, A.: Generation of t-ary trees with ballot-sequences. Int. J. Comput. Math. 80, 1243–1249 (2003)MathSciNetMATHCrossRefGoogle Scholar
  3. 3.
    Er, M.C.: Lexicographic listing and ranking t-ary trees. Comput. J. 30, 569–572 (1987)MathSciNetMATHCrossRefGoogle Scholar
  4. 4.
    Er, M.C.: A simple algorithm for generating non-regular trees in lexicographic order. Comput. J. 31, 61–64 (1988)MathSciNetMATHCrossRefGoogle Scholar
  5. 5.
    Korsh, J.F.: Loopless generation of k-ary tree sequences. Inform. Process. Lett. 52, 243–247 (1994)MathSciNetCrossRefGoogle Scholar
  6. 6.
    Korsh, J.F., LaFollette, P.: Loopless generation of Gray codes for k-ary trees. Inform. Process. Lett. 70, 7–11 (1999)MathSciNetMATHCrossRefGoogle Scholar
  7. 7.
    Korsh, J.F., LaFollette, P.: A loopless Gray code for rooted trees. ACM Trans. Algorithms 2, 135–152 (2006)MathSciNetCrossRefGoogle Scholar
  8. 8.
    Korsh, J.F., Lipschutz, S.: Shift and loopless generation of k-ary trees. Inform. Process. Lett. 65, 235–240 (1998)MathSciNetCrossRefGoogle Scholar
  9. 9.
    Roelants van Baronaigien, D.: A loopless Gray-code algorithm for listing k-ary trees. J. Algorithms 35, 100–107 (2000)MathSciNetMATHCrossRefGoogle Scholar
  10. 10.
    Roelants van Baronaigien, D., Ruskey, F.: Generating t-ary trees in A-order. Inform. Process. Lett. 27, 205–213 (1988)MathSciNetMATHCrossRefGoogle Scholar
  11. 11.
    Ruskey, F.: Generating t-ary trees lexicographically. SIAM J. Comput. 7, 424–439 (1978)MathSciNetMATHCrossRefGoogle Scholar
  12. 12.
    Savage, C.D.: A survey of combinatorial Gray codes. SIAM Review 39, 605–629 (1997)MathSciNetMATHCrossRefGoogle Scholar
  13. 13.
    Trojanowaki, A.E.: Ranking and listing algorithms for k-ary trees. SIAM J. Comput. 7, 492–509 (1978)MathSciNetCrossRefGoogle Scholar
  14. 14.
    Wu, R.-Y., Chang, J.-M., Chang, C.-H.: Ranking and unranking of non-regular trees with a prescribed branching sequence. Math. Comput. Modelling 53, 1331–1335 (2011)MathSciNetMATHCrossRefGoogle Scholar
  15. 15.
    Wu, R.-Y., Chang, J.-M., Wang, Y.-L.: Loopless Generation of non-regular trees with a prescribed branching sequence. Comput. J. 53, 661–666 (2010)CrossRefGoogle Scholar
  16. 16.
    Wu, R.-Y., Chang, J.-M., Wang, Y.-L.: Ranking and unranking of t-ary trees using RD-sequences. IEICE Trans. Inform. Sys. E94-D, 226–232 (2011)CrossRefGoogle Scholar
  17. 17.
    Xiang, L., Ushijima, K., Tang, C.: Efficient loopless generation of Gray codes for k-ary trees. Inform. Process. Lett. 76, 169–174 (2000)MathSciNetMATHCrossRefGoogle Scholar
  18. 18.
    Zaks, S.: Lexicographic generation of ordered trees. Theore. Comput. Sci. 10, 63–82 (1980)MathSciNetMATHCrossRefGoogle Scholar
  19. 19.
    Zaks, S.: Generation and ranking of k-ary trees. Inform. Process. Lett. 14, 44–48 (1982)MathSciNetCrossRefGoogle Scholar
  20. 20.
    Zaks, S., Richards, D.: Generating trees and other combinatorial objects lexicographically. SIAM J. Comput. 81, 73–81 (1979)MathSciNetCrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2013

Authors and Affiliations

  • Ro-Yu Wu
    • 1
  • Jou-Ming Chang
    • 2
  • An-Hang Chen
    • 2
  • Ming-Tat Ko
    • 3
  1. 1.Department of Industrial ManagementLunghwa University of Science and TechnologyTaoyuanTaiwan, ROC
  2. 2.Institute of Information and Decision SciencesNational Taipei College of BusinessTaipeiTaiwan, ROC
  3. 3.Institute of Information ScienceAcademia SinicaTaipeiTaiwan, ROC

Personalised recommendations