简体   繁体   English

霍夫曼编码树的最大高度

[英]Maximum height of a huffman coding tree

What is the maximum height of a tree made with the huffman coding algorithm assuming that all bytes are accepted into it.假设所有字节都被接受到其中,使用霍夫曼编码算法制作的树的最大高度是多少。

I'm curious since I somehow managed to get a path of 9 bits when I tried to compress I file which I generated randomly.我很好奇,因为当我尝试压缩我随机生成的文件时,我以某种方式设法获得了 9 位的路径。 Which means that I essentially inflate the size of the file.这意味着我基本上夸大了文件的大小。 Though there might be a problem somewhere in the program that I don't know about.尽管程序中的某个地方可能存在我不知道的问题。

If by "all bytes" you mean all 256 possible byte values as your set of symbols, the answer is that the maximum depth, and so the length of the longest code, is 255.如果“所有字节”是指所有 256 个可能的字节值作为符号集,则答案是最大深度以及最长代码的长度是 255。

To get this though requires very large numbers for the frequencies of the symbols.不过,要做到这一点,需要非常大的符号频率数字。 The sequence that does this with the smallest total count are the Lucas numbers, with the zeroth Lucas number of 2 broken into two 1's.以最少的总计数执行此操作的序列是卢卡斯数,第零个卢卡斯数 2 分成两个 1。 So:所以:

1, 1, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123, 199, ...

where the terms starting with 4 are the sum of the previous two terms, just like the Fibonacci sequence.其中以 4 开头的项是前两项之和,就像斐波那契数列一样。 The last term in that sequence for 256 symbols is:该序列中 256 个符号的最后一项是:

121020968315000050139390193037122554865361969834971243

About 10 53 .大约 10 53

As for your random data of all possible bytes, in general you can't compress it.至于您所有可能字节的随机数据,通常您无法压缩它。 However if you got one code of 9 bits in length, then that means the code is at least as good as assigning 8 bits to all of the symbols.但是,如果您得到一个长度为 9 位的代码,那么这意味着该代码至少与为所有符号分配 8 位一样好。 So you did not inflate the file, but rather left it the same size or reduced it by a bit or more.所以你没有膨胀文件,而是让它保持相同的大小或减少一点或更多。 However that's not taking into account the fact that you have to also send the code itself so that the decoder on the other end can decode.但是,这并没有考虑到您还必须发送代码本身以便另一端的解码器可以解码这一事实。 That will more than kill any tiny bit of compression you got.这不仅会杀死您获得的任何一点点压缩。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM