If the Huffman tree of degree m, the number of leaf nodes is n, the number of non-leaf nodes is solved

If in a Huffman tree with degree m, the number of leaf nodes is n, then the number of non-leaf nodes is ()
A: There are n leaf nodes, that is, nodes with degree 0; suppose the degree is The number of nodes of m is x, then x+n=mx+1; that is, x=n-1/m-1;
if n-1 cannot be divisible, that is, the given data cannot directly construct the optimal m-ary tree At this time, you need to add some data that does not affect the establishment of the tree, you can add 0; the number of additions is (m-1)-((n-1)%(m-1)). So finally x should be ⌈n-1/m-1⌉, which is rounded up;

Guess you like

Origin blog.csdn.net/lthahaha/article/details/109269319