Skip to main content
Log in

Improved algorithms for ranking and unranking (km)-ary trees in B-order

  • Published:
Journal of Combinatorial Optimization Aims and scope Submit manuscript

Abstract

Du and Liu (Eur J Comb 28:1312–1321, 2007) introduced (km)-ary trees as a generalization of k-ary trees. In a (km)-ary tree, every node on even level has degree k (i.e., has k children), and every node on odd level has degree m (which is called a crucial node) or is a leaf. In particular, a (km)-ary tree of order n has exactly n crucial nodes. Recently, Amani and Nowzari-Dalini (Bull Iranian Math Soc 45(4):1145–1158, 2019) presented a generation algorithm to produce all (km)-ary trees of order n in B-order using Zaks’ encoding, and showed that the generated ordering of this encoding results in a reverse-lexicographical ordering. They also proposed the corresponding ranking and unranking algorithms for (km)-ary trees according to such a generated ordering. These algorithms take \(\mathcal {O}(kmn^2)\) time and space for building a precomputed table in which (km)-Catalan numbers (i.e., a kind of generalized Catalan numbers) are stored in advance. Then, each ranking and unranking algorithm can be performed subsequently in \(\mathcal {O}(n)\) and \(\mathcal {O}(n\log n)\) time, respectively. In this paper, we revisit the ranking and unranking problems. With the help of an encoding scheme called “right-distance” introduced by Wu et al. (Math Comput Model 53:1331–1335, 2011a; IEICE Trans Inf Syst E94–D:226–232, 2011b), we propose new ranking and unranking algorithms for (km)-ary trees of order n in B-order using Zaks’ encoding. We show that both algorithms can be improved in \(\mathcal {O}(kmn)\) time and \(\mathcal {O}(n)\) space without building the precomputed table.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Fig. 1
Fig. 2
Fig. 3
Fig. 4
Fig. 5
Fig. 6
Fig. 7
Fig. 8
Fig. 9
Fig. 10

Similar content being viewed by others

References

  • Amani M (2018) Gap terminology and related combinatorial properties for AVL trees and Fibonacci-isomorphic trees. AKCE Int J Graphs Comb 15:14–21

    Article  MathSciNet  Google Scholar 

  • Amani M, Nowzari-Dalini A (2015a) Ranking and unranking algorithm for neuronal trees in B-order. J Phys Sci 20:19–34

    MathSciNet  MATH  Google Scholar 

  • Amani M, Nowzari-Dalini A (2015b) Generation, ranking and unranking of ordered trees with degree bounds. In: Proceedings of DCM 2015, Electronic proceedings in theoretical computer science, vol 204, pp 31–45

  • Amani M, Nowzari-Dalini A (2019) Efficient generation, ranking, and unranking of \((k, m)\)-ary trees in B-order. Bull Iranian Math Soc 45(4):1145–1158

    Article  MathSciNet  Google Scholar 

  • Amani M, Nowzari-Dalini A, Ahrabian H (2014) Generation of neuronal trees by a new three letters encoding. Comput Inf J 33:1428–1450

    MathSciNet  MATH  Google Scholar 

  • Du RRX, Liu F (2007) \((k, m)\)-Catalan numbers and hook length polynomials for plane trees. Eur J Comb 28:1312–1321

    Article  MathSciNet  Google Scholar 

  • Li L (1986) Ranking and unranking AVL trees. SIAM J Comput 15:1025–1035

    Article  MathSciNet  Google Scholar 

  • Pai K-J, Chang J-M, Wu R-Y, Chang S-C (2019) Amortized efficiency of generation, ranking and unranking left-child sequences in lexicographic order. Discrete Appl Math 268:223–236

    Article  MathSciNet  Google Scholar 

  • Pallo J (1987) Generating trees with \(n\) nodes and \(m\) leaves. Int J Comput Math 21:133–144

    Article  Google Scholar 

  • Seyedi-Tabari E, Ahrabian H, Nowzari-Dalini A (2010) A new algorithm for generation of different types of RNA. Int J Comput Math 87:1197–1207

    Article  MathSciNet  Google Scholar 

  • Stanley RP (1999) Enumerative combinatorics, vol 2. Cambridge University Press, Cambridge

    Book  Google Scholar 

  • Wu R-Y, Chang J-M, Wang Y-L (2006) A linear time algorithm for binary tree sequences transformation using left-arm and right-arm rotations. Theor Comput Sci 355:303–314

    Article  MathSciNet  Google Scholar 

  • Wu R-Y, Chang J-M, Wang Y-L (2010) Loopless generation of non-regular trees with a prescribed branching sequence. Comput J 53:661–666

    Article  Google Scholar 

  • Wu R-Y, Chang J-M, Chang C-H (2011a) Ranking and unranking of non-regular trees with a prescribed branching sequence. Math Comput Model 53:1331–1335

    Article  MathSciNet  Google Scholar 

  • Wu R-Y, Chang J-M, Wang Y-L (2011b) Ranking and unranking of \(t\)-ary trees using RD-sequences. IEICE Trans Inf Syst E94–D:226–232

    Article  Google Scholar 

  • Wu R-Y, Chang J-M, Chen A-H, Liu C-L (2013) Ranking and unranking \(t\)-ary trees in a Gray-code order. Comput J 56:1388–1395

    Article  Google Scholar 

  • Wu R-Y, Chang J-M, Chan H-C, Pai K-J (2014) A loopless algorithm for generating multiple binary tree sequences simultaneously. Theor Comput Sci 556:25–33

    Article  MathSciNet  Google Scholar 

  • Zaks S (1980) Lexicographic generation of ordered trees. Theor Comput Sci 10:63–82

    Article  MathSciNet  Google Scholar 

Download references

Acknowledgements

The research was partially supported by MOST Grants 108-2115-M-262-001 (R.-Y. Wu), 107-2221-E-141-002 (R.-S. Chang) and 107-2221-E-141-001-MY3 (J.-M. Chang) from the Ministry of Science and Technology, Taiwan.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Jou-Ming Chang.

Additional information

Publisher's Note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Appendix A: Proof of Theorem 5

Appendix A: Proof of Theorem 5

The proof is by induction on \(\ell +d\). The result is trivially true for \(d=0\) (i.e., \(B_{\ell ,0}=0\), the case in the amendment of Eq. (3.1)) or \(\ell \leqslant 1\) (i.e., \(B_{0,d}=1\) for \(d\ne 0\) and \(B_{1,d}=d\), the first two conditions of Eq. (3.1)). We now consider \(\ell \geqslant 2\) and \(d\geqslant 1\) and suppose that the theorem holds for \(B_{\ell ',d'}\) with \(\ell '<\ell \) or \(d'<d\). There are two case as follows:

If \(d=1\), by the third condition of Eq. (3.1) and the induction hypothesis, we have

$$\begin{aligned} B_{\ell ,1}= & {} B_{\ell -1,km} =\frac{km}{km(\ell -1)+km}{km(\ell -1)+km\atopwithdelims ()\ell -1} =\frac{1}{\ell }{km\ell \atopwithdelims ()\ell -1} \\= & {} \frac{1}{\ell }\cdot \frac{km\ell \,!}{(\ell -1)!\ (km\ell -\ell +1)!} = \frac{1}{km\ell +1}\cdot \frac{(km\ell +1)!}{\ell \,!\,(km\ell +1-\ell )!}\\= & {} \frac{1}{km\ell +1}{km\ell +1\atopwithdelims ()\ell }. \end{aligned}$$

Otherwise (i.e., \(\ell ,d>1\)), by the last condition of Eq. (3.1) and the induction hypothesis, we have

$$\begin{aligned} B_{\ell ,d}= & {} B_{\ell ,d-1}+B_{\ell -1,km+d-1} \\= & {} \frac{d-1}{km\ell +d-1}{km\ell +d-1\atopwithdelims ()\ell }\\&+\frac{km+d-1}{km(\ell -1)+km+d-1}{km(\ell -1)+km+d-1\atopwithdelims ()\ell -1}\\= & {} \frac{d-1}{km\ell +d-1}{km\ell +d-1\atopwithdelims ()\ell } +\frac{km+d-1}{km\ell +d-1}{km\ell +d-1\atopwithdelims ()\ell -1}\\= & {} \left( \frac{d-1}{km\ell +d-1}\cdot \frac{km\ell +d-\ell }{km\ell +d}+ \frac{km+d-1}{km\ell +d-1}\cdot \frac{\ell }{km\ell +d}\right) {km\ell +d\atopwithdelims ()\ell }\\= & {} \frac{d}{km\ell +d}{km\ell +d\atopwithdelims ()\ell }. \end{aligned}$$

This completes the proof. \(\square \)

Rights and permissions

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Chang, YH., Wu, RY., Chang, RS. et al. Improved algorithms for ranking and unranking (km)-ary trees in B-order. J Comb Optim 44, 1495–1510 (2022). https://doi.org/10.1007/s10878-019-00469-z

Download citation

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s10878-019-00469-z

Keywords

Mathematics Subject Classification

Navigation