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?
One easy way of doing it could be like so:
Convert the natural number n into base k to get $n_k$.
Now suppose that the digits of $n_k$ are $(0,d_1,d_2,...,d_m)$.
Example, for n=5 and k=4, digits of $n_k$ would be (0,1,1).
Coming to the tree now.
Let the tree's root node have a value of $0$, so, if $n=0$ then we simply return the root.
If $n\ne0$, then we proceed to generate our tree from root. From the root, we take $d_1$$^{th}$ child node, and from there take $d_2$$^{th}$ child node and then continue doing it. That is, from $d_i$$^{th}$ node we would take $d_{i+1}$$^{th}$ child node of $d_i$.
For instance, when k=4, following is the graph, where vertex labels represent which $n_k$ would bring you there:
Now, when I want a graph for, say, 10 - I simply give the subgraph of above graph having the following vertices: 0 (root), 02 and 022.
Also observe that each vertex in the graph has a unique base-k value, the next graph shows these values in base-10: