Probably not what you want because this involves lookup tables. But there is a chance that this solves your problem, so I give it a shot.
First we generate a 3-ary tree of the desired depth (I store it as a directed graph for later use):
base = 3;
maxlevel = 3;
descendantcount[base_, maxlevel_] :=
Quotient[base^(maxlevel + 1) - 1, base - 1];
T = Graph[ DirectedEdge @@@ EdgeList[KaryTree[descendantcount[base, maxlevel], base]]];
Next we build a lookup table IndexToDFS
that map the index of the currect vertex ordering (which is 1-based breadth-first ordering, btw.) to the 0-based depth-first ordering. In the same go we build the inverse lookup DFSToIndex
. If everything were 1-based, then one could use simple arrays; but you want 0-basedness, so we need to use Association
as data structure).
counter = 0;
IndexToDFS = Association[];
DFSToIndex = Association[];
child[dfs_, k_] :=
IndexToDFS[VertexOutComponent[T, DFSToIndex[dfs], 1][[k + 2]]];
DepthFirstScan[T, 1,
{"PrevisitVertex" -> ((
AssociateTo[IndexToDFS, # -> counter];
AssociateTo[DFSToIndex, counter -> #];
++counter
) &)
}];
Graph[T,
DirectedEdges -> True,
VertexLabels -> Normal@IndexToDFS,
VertexSize -> .2,
GraphLayout -> {"LayeredEmbedding", LayerSizeFunction -> (4 &)}
]
Now children can be "computed" with the following method:
child[dfs_, k_] := IndexToDFS[VertexOutComponent[T, DFSToIndex[dfs], 1][[k + 2]]];
For the example given:
{child[10, 0], child[10, 1], child[10, 2]}
{11, 12, 13}