1
$\begingroup$

Imagine a descendants tree where all nodes are either 1, 2 or 3. Each node has two descendants, all numbers except itself. Given a row $n$ how many nodes are the same as our original (first) node?

Example:

Since for each node different from 1 in row $i$, row $i+1$ has exactly one node equal to $1$ we can work out that $S(n+1)=2^n - S(n)$ and that $S(0)=1$ where S is the number of nodes equal to our original.

  • 0
    What does row $n$ mean? Does it means height of tree?2017-02-20
  • 0
    Yes n is the height of the tree2017-02-20
  • 0
    Hint(s): Row $n$ has $2^n$ nodes (numbering starts from $n=0$). For each node different from $1$ in row $i$, row $i+1$ has exactly one node equal to $1$. Try to work out a recurrence relation.2017-02-20
  • 1
    Could we say that $S(n)=2^n-S(n-1)$ where S(a) is the number of nodes similar to let's say 1 in the $a$th row?2017-02-20

2 Answers 2

2

WLOG let root is of type $1$.

Let $f(k)$ denote number of nodes with type $1$ in level k and $g(k)$ be number of nodes of type other than $1$.

So, in level zero(root) there is only one node of type $1$ and zero nodes of other types. So, $f(0) = 1$ and $g(0) = 0$.

Now, $1$ can be the child of only $2$ and $3$. So, number of $1$'s at level $k+1$ is equal to number of $2$'s and $3$'s at level $k$. So, $f(k+1) = g(k)$.

And number of $2$'s and $3$'s at level $k$ is number of nodes in level $k$ - number of nodes of type $1$. So, $g(k) = 2^k - f(k)$. So, $$f(k+1) = 2^k - f(k)$$ $$f(k+1) + f(k) = 2^k$$

So, total number of nodes of type $1$ in a tree of height $n$ is equal to $$f(0) + f(1) + ...... f(n)$$ $$= (f(n) + f(n-1)) + (f(n-2) + f(n-3)) + .....$$ $$= 2^{n-1} + 2^{n-3} + .....$$

And it is equal to $\dfrac{2^{n+1} - 1}{3}$ when n is odd and $\dfrac{2^{n+1} + 1}{3}$ when n is even.

  • 0
    From here how can we find $f(n)$?2017-02-20
  • 0
    We have computed the value $f(0) + f(1) + ... + f(n)$. So, $f(n) = (f(n) + f(n-1) + .... f(0)) - (f(n-1) + f(n-2) + ... f(0))$.2017-02-20
1

Here's a little help. If we suppose that ${S_{n}}$ is the number of nodes in $n$-th row that are the same like our root node then the recursion is ${S_{n}} = 2^{n-1} - {S_{n-1}}, {S_{o}}= 1$.

We can interpret that this way: If node $1$ is our root node then in $n$-th node we have to look up in previous row and see how many nodes are different from node $1$. We know that there are $2^{n-1}$ nodes in previous row and we have to exclude nodes with 1, that means ${S_{n-1}}$ of them. In $0$-th row we have exactly one node equal to our first root node so that is the initial value. Now you can solve the recursion in various ways and you get the answer $\frac{2(-1)^{n}+2^{n}}{3}$