有效的霍夫曼码? [英] Valid Huffman Codes?
问题描述
我正在尝试解决霍夫曼编码问题,但我不确定我是否完全理解该主题.我想弄清楚以下是否是有效的霍夫曼代码:
I'm trying to solve a Huffman Coding problem, but I'm not completely sure I understand the topic completely. I am trying to figure out if the following are is a valid Huffman Code:
A: 0
B: 01
C: 11
D: 110
E: 111
我的想法是它无效,因为 A 或 1 会侵犯 B 或 01.不过我并不肯定.有人可以启发我吗?
What I'm thinking is that it is not valid, because A, or 1, would infringe on B, or 01. I'm not positive though. Could someone enlighten me on this?
对不起,我想将 A 输入为 0 而不是 1.
I'm sorry I meant to type A as 0 and not 1.
推荐答案
没有.霍夫曼码是一个前缀码,这意味着任何码都不能是任何其他码的前缀.在您的示例中,A 是 B 的前缀,C 是 D 和 E 的前缀.
No. A Huffman code is a prefix code, which means that no code can be a prefix of any other code. In your example, A is a prefix of B, and C is a prefix of both D and E.
有效的前缀代码为:
A: 0
B: 10
C: 11
这就是长度为 1、2 和 2 的代码所能达到的范围.任何其他代码都将是这些代码的前缀.不可能有长度为 1、2、2、3 和 3 的前缀代码.
That's as far as you can go with codes of length 1, 2, and 2. Any other codes would be a prefix of those. It is not possible to have a prefix code with lengths 1, 2, 2, 3, and 3.
这是五个符号的有效前缀代码:
This is a valid prefix code for five symbols:
A: 0
B: 10
C: 110
D: 1110
E: 1111
是这样的:
A: 00
B: 01
C: 10
D: 110
E: 111
这篇关于有效的霍夫曼码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!