For an even integer , merge the two least weights once, then repeatedly merge three least weights until only the tree root remains. The initial binary merge leaves an odd number of weighted objects, so the preceding algorithm applies. The initial merged tree parent has two tree children; subsequent tree parents have three. Equivalently, add one zero-weight dummy symbol, run the odd-leaf ternary Huffman coding algorithm, and remove its codeword afterwards. The dummy contributes nothing to expected codeword length.
Here the first merge joins the two weights , producing . The three remaining weights are , and merge directly into the tree root. Assigning the first two tree root branches to the original symbols of weights and givesThe merge-weight check gives as well. For , the first merge is already the tree root; for , outside this case with an even number of symbols, the usual temporary reduced-problem convention would permit an empty word.
Articles by others on the same topic
There are currently no matching articles.