Abstract

A family of (k, m)-ary trees was firstly introduced by Du and Liu when they studied hook length polynomial for plane trees. Recently, Amani and Nowzari-Dalini presented a generation algorithm to produce (k, m)-ary trees of order n encoding by Z-sequences in reverse lexicographic order. In this paper, we propose a loopless algorithm to generate all such Z-sequences in Gray code order. Hence, the worst-case time complexity of generating one Z-sequence is $${\mathcal {O}}(1)$$ , and the space requirement of our algorithm is $$2n+{\mathcal {O}}(1)$$ . Moreover, based on this ordering, we also provide ranking and unranking algorithms. The ranking algorithm can be run in $${\mathcal {O}}(\max \{kmn,n^2\})$$ time and $${\mathcal {O}}(kmn)$$ space, whereas the unranking algorithm requires $${\mathcal {O}}(kmn^2)$$ time and space.

Full Text
Published version (Free)

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call