Abstract
Du and Liu (Eur J Comb 28:1312–1321, 2007) introduced (k, m)-ary trees as a generalization of k-ary trees. In a (k, m)-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 (k, m)-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 (k, m)-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 (k, m)-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 (k, m)-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 (k, m)-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.










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
Amani M, Nowzari-Dalini A (2015a) Ranking and unranking algorithm for neuronal trees in B-order. J Phys Sci 20:19–34
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
Amani M, Nowzari-Dalini A, Ahrabian H (2014) Generation of neuronal trees by a new three letters encoding. Comput Inf J 33:1428–1450
Du RRX, Liu F (2007) \((k, m)\)-Catalan numbers and hook length polynomials for plane trees. Eur J Comb 28:1312–1321
Li L (1986) Ranking and unranking AVL trees. SIAM J Comput 15:1025–1035
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
Pallo J (1987) Generating trees with \(n\) nodes and \(m\) leaves. Int J Comput Math 21:133–144
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
Stanley RP (1999) Enumerative combinatorics, vol 2. Cambridge University Press, Cambridge
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
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
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
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
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
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
Zaks S (1980) Lexicographic generation of ordered trees. Theor Comput Sci 10:63–82
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
Corresponding author
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
Otherwise (i.e., \(\ell ,d>1\)), by the last condition of Eq. (3.1) and the induction hypothesis, we have
This completes the proof. \(\square \)
Rights and permissions
About this article
Cite this article
Chang, YH., Wu, RY., Chang, RS. et al. Improved algorithms for ranking and unranking (k, m)-ary trees in B-order. J Comb Optim 44, 1495–1510 (2022). https://doi.org/10.1007/s10878-019-00469-z
Published:
Issue Date:
DOI: https://doi.org/10.1007/s10878-019-00469-z
Keywords
- (k, m)-Ary trees
- Ranking/unranking algorithms
- Zaks’ sequences
- RD-sequences
- Lexicographic/reverse-lexicographic order
- Amortized cost