In binary tree, number of nodes with two children when number of leaves is given
Hint:
- For any tree: $|E| = |V|-1$.
- For any graph $2|E| = \sum_{v \in V} \deg(v)$.
- A vertex is a leaf if and only if it's degree is $1$.
- Except for root, the two-children nodes have degree $3$.
- Intuition: start with a path (each vertex has degree 2, except for two leaves at the ends); now, each time you change a vertex from degree 2 to degree 3, you have make some other vertex of degree 2 into degree 1, so that the sum of degrees is constant.
I hope this helps $\ddot\smile$
Let the number of leaves be $l$. Let the number of nodes with exactly two children be $d_2$ and with exactly one children be $d_1$.
Total degree
$d=l+3d_2+2d_1-1$ (as all nodes with 2 children have degree 3 except the root)
Number of nodes $n=d_2+d_1+l$
Number of edges $e=\frac{d}{2}=\frac{l+3d_2+2d_1-1}{2}$
Number of edges in a tree $e=n-1$
$\therefore \frac{l+3d_2+2d_1-1}{2}=d_2+d_1+l-1$
$\therefore d_2=l-1$
This is the result which I was trying to prove in this question.