i have a full d-node tree (by that mean a tree that each node has exactly d nodes as kids). My question is, if i get a random k node of this tree, in which position do i get his kids and his parent?
For example, if i have a full binary tree, the positions that i can find the parent,left and right kid of the k node are $\dfrac k2, 2k, 2k+1$ respectively.
Thanks in advance.
Start by labeling your $k$-ary tree with the root as $0$, and continue in a breath-first-search pattern.
Given a node $n$, with index $n\text{.i}$, $n$'s children have indices: $$\{(n\text{.i})k+1,\, (n\text{.i})k+1,\, \ldots,\, (n\text{.i})k + k\}$$
We can also see that given a node $n$ with index $n\text{.i}\gt0$, we can find the index of the parent by the formula: $$p\text{.i}=\left\lfloor\frac{n\text{.i} - 1}{k}\right\rfloor$$
I haven't proved these, but these formulas appear to be correct based on several different drawings.