Alex Rivera | Logout

What is the total number of nodes in a full k-ary tree, in terms of the number of leaves?

Asked 2011-10-20T21:19:48.943
41

I am doing a unique form of Huffman encoding, and am constructing a k-ary (in this particular case, 3-ary) tree that is full (every node will have 0 or k children), and I know how many leaves it will have before I construct it. How do I calculate the total number of nodes in the tree in terms of the number of leaves?

I know that in the case of a full binary tree (2-ary), the formula for this is 2L - 1, where L is the number of leaves. I would like to extend this principle to the case of a k-ary tree.

Edit
Report

1 Answer

0

The formula for 2L-1 that you mentioned comes from looking on a full, complete and balanced binary tree: on the last level you have 2^h leafs, and on the other levels: 1+2+4+....+2^(h-1) = 2^h -1 leafs. When you "mess" levels in the tree and create an unbalanced one, then the number of internal nodes that you have doesn't change.

In 3-ary tree its the same logic: on the last level you have 3^h leafs, and on the other levels: 1+3+9+....+3^(h-1)= (3^h -1 )/2, that means that on a 3-ary tree you have 1.5*L - 0.5 leafs (and this make sence- because the degree is larger you need less internal nodes). I thing that also here, when you mess up levels in the tree you will still need the same number of internal nodes.

Hope that it helps you

answered 2011-10-20T22:06:56.103

Your Answer