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


I am making a unique form of encoding encoding, and I am creating a karri (in this special case , 3-Arri) The tree that is full (there will be 0 or Kashmir children in each node), and I know that before I create it, how many leaves will it have. How do I calculate the total nodes in the tree in terms of the number of leaves?

I know that in the case of a complete binary tree (2-saw), its formula is 2 L - 1, where L is the number of leaves I have this principle in the case of a K-Arya tree I would like to expand.

Think about how results for a complete binary tree prove, and you will see that How to do it in general. For the complete binary tree, the height h says, the number of nodes is N

N = 2 ^ {h + 1} - 1

Why? Because the first level has 2 ^ 0 nodes, the second level has 2 ^ 1 nodes, and, in general, k th level < Code> 2 ^ {k-1} nodes adds them all to h + 1 level (so high h )

  N = 1 + 2 + 2 ^ 2 + 2 ^ 3 + ... + 2 ^ h = (2 ^ {h + 1} - 1) / (2 - 1) = 2 ^ {h + 1 } Total number of leaves  L  is the number of nodes at the final level, so  l = 2 ^ h . Therefore, by replacement, we do not have 

  N = 2 * L - 1  

for k - tree, nothing Changes but 2 then

  N = 1 + k + k ^ 2 + k ^ 3 + ... + k ^ h = (k ^ {h + 1  
  N = (k * L - 1) / (k - 1) l = k ^ h  

and therefore a little bit of algebra < 1) The last step can be obtained / (k-1)


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -