1
$\begingroup$

Is there an algorithmic way to map the natural numbers to unique k-ary trees?

I am familiar with the work of Tychonievich who created a mapping from integers to binary trees. https://www.cs.virginia.edu/~lat7h/blog/posts/434.html

Is there something similar for k-ary trees?

$\endgroup$
5
  • $\begingroup$ There is more than one way to count k-ary trees, meaning that the numeric values will be different (there are different equivalence relations...). Would you spell your definition explicitly in your Question? $\endgroup$
    – Wlod AA
    Commented Nov 22, 2019 at 4:20
  • $\begingroup$ It seems that you can follow the 2-ary solution from the link you have provided. I don't see any complication, the generalization seems to be straightforward. $\endgroup$
    – Wlod AA
    Commented Nov 22, 2019 at 4:50
  • $\begingroup$ I have tried extending it to the case of an n-ary tree and encountered a complication. At the end of the algorithm suggested by Tychonievich, he splits the integer into two separate integers, one for the right child and another for the left child. If I have an n-ary tree, it is not clear how many children there would be. $\endgroup$
    – Sohrab T
    Commented Nov 22, 2019 at 17:53
  • 1
    $\begingroup$ Do everything by analogy. You'll use base k notation. You'll have k children each time (some of them may be empty, corresponding to digit 0. (I better go back to that link and have another look). $\endgroup$
    – Wlod AA
    Commented Nov 22, 2019 at 18:24
  • 1
    $\begingroup$ Yes, given a non-negative integer, you extract k new integers (corresponding to children) by collecting the digits on the position = r mod k to form the r-th integer. $\endgroup$
    – Wlod AA
    Commented Nov 22, 2019 at 18:34

1 Answer 1

3
$\begingroup$

If you search for "ranking $k$-ary trees" or "ranking $t$-ary trees" you will find several published papers on this. For example:

This

This

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .