In a complete k -ary tree, every internal node has exactly k children. The number of leaves in such a tree with n internal nodes is _________ .
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Yes a bit more generalized
@Char Galvez You are in brilliant.org now you won't be lacking ideas. Go ahead.
More generalized: every node has $k$ children, so there are $nk$ leaves. But this counts all $n$ nodes twice, and the one root, so we subtract that to obtain $nk - n - 1$, or $n(k-1) + 1$.
Can you help me? 😭 We have this Mathematical Investigation subject. It's either we make mathematical modeling or games related to math or make another formula. I came up with another divisibility rule for 9 but I don't know how to do it. Huhu. Help me please.
Like Satyabrata I 'solved' the problem by checking a binary tree and ticking the formula which worked. Now that we know this formula works for (at least two!) binary trees it would be nice to prove it for a l l k _ary trees! I found a simple proof by induction -
Let L ( n ) be the number of leaves on a complete k _ary tree with n internal nodes. Assume as our hypothesis that, for some number of internal nodes, r
L ( r ) = r ( k − 1 ) + 1
Now choose any leaf, convert it to an internal node and draw from it k branches. This creates one more internal node, destroys one leaf and creates k new leaves. So
L ( r + 1 ) = L ( r ) + k − 1 = r ( k − 1 ) + 1 + ( k − 1 ) = ( r + 1 ) ( k − 1 ) + 1
This has the same form as the induction hypothesis with r replaced by r + 1 .
Note also that the hypothesis holds when r = 1 because a tree with one internal node (the root) has k branches and k leaves. And indeed our formula gives
L ( 1 ) = 1 ( k − 1 ) + 1 = k
Everything is now set up to complete the proof by invoking the principle of mathematical induction to get
L ( n ) = n ( k − 1 ) + 1
as required.
Hey good solution man!!
Problem Loading...
Note Loading...
Set Loading...
Any node which has children is called internal node. So, In case of tree with more than one node, root node is also an internal node.
Now,let's solve the problem using binary tree. In case of binary tree,k =2. Suppose, binary tree has 7 internal nodes.
ROOT
/ \
N N
/ \ / \
N N N N
/ \ / \ / \ / \
L L L L L L L L
N=Internal Node L=Leaf
So, n = 7 and L=8
(I) nk = 7*2 = 14 wrong
(II) (n-1)k+1 = (7-1)*2+1 = 13 wrong
(III) n(k-1)+1 = 7 (2-1)+1 = 8 right*
(IV) n(k-1) = 7*(2-1) = 7 wrong
Cheers!!