Formula for number of "root" nodes in a tree where Parent shares child nodes?

1.1k Views Asked by At

If I have a tree like this:

{a},{b,c},{d,e,f},{g,h,i,j}

in this case we have a total of 10 nodes. Is there any equation where given "10" I can calculate how many bottom nodes there are (answer: "4" in my example)?

1

There are 1 best solutions below

2
On BEST ANSWER

Recall that the $n$th triangular number is given by: $$ T_n = \frac{n(n + 1)}{2} $$ You appear to be asking for the inverse of this function. By taking the positive version of the above function's inverse, we obtain the following formula: $$ \frac{\sqrt{8n + 1} - 1}{2} $$

Indeed, for $n = 10$ nodes, we find that the number of levels is: $$ \frac{\sqrt{8(10) + 1} - 1}{2} = \frac{\sqrt{81} - 1}{2} = \frac{8}{2} = 4 $$ as desired.