[Math] Find Branching factor of tree graph

graph theorytrees

Imagine I have two numbers $m$ and $n$ now I can build tree graph with branching factor of n in this way:
The root of tree is m, in the second level of three each node has value $$k= \frac{m}{n+1}$$ and in the third level each node has value of $$k = \frac{k}{n+1}$$ and so on continue this process until the last level of tree which each node values is 1.
Now Given number of Ones which means leaf of tree and $m$ I want to find branching factor of three which means $n$ see picture below for more explanation
enter image description here

In this picture $m$ is $16$ and number of ones is $9$ as I said above in the second level of tree each node has value of $k= \frac{16}{3+1}$ which here is 4 and in the third level of tree each node is $k= \frac{4}{3+1}$ which here is 1 that is the last level of tree because each node value is 1 and the answer $n$ is $3$ branching factor of tree

Best Answer

Going down with each level you divide your number by the same factor, namely $n+1$. Going up you reverse this, which means you multiply by $n+1$.

This means that if $h$ is the height of the tree including leaves (i.e. your example has height 3) and you start with $1$, then $$m = (n+1)^{h-1} \cdot 1.$$

In your case that is $16 = 4^{3-1}$. Furthermore, with each level you get $n$ more nodes, thus the number of leaves is

$$l = n^{h-1},$$

in your case $9 = 3^{3-1}$. That makes two equations with two unknowns ($n$ and $h$). First we transform the second one into $$h-1 = \frac{\log l}{\log n}$$ and substitute into the first: $$m = (n+1)^{\frac{\log l}{\log n}}$$ that is $$\frac{\log m}{\log l} = \frac{\log (n+1)}{\log n}.$$ As $m > l > 1$ for the solution to exist (except some edge cases), we consider function $\frac{\log (x+1)}{\log x}$ for $x > 1$ where it is continuous, strictly decreasing and even convex. Thus, you can use any of the standard techniques to search for the solution.

I hope this helps $\ddot\smile$

Related Question