一家网络公司使用压缩技术对消息进行编码,然后再通过网络进行传输。假设消息包含以下字符及其频率:
character Frequency
a 5
b 9
c 12
d 13
e 16
f 45
注意:输入消息中的每个字符占用1个字节。
如果使用的压缩技术是霍夫曼编码,则消息中将保存多少位?
(A) 224
(B) 800
(C) 576
(D) 324答案: (C)
解释:
Total number of characters in the message = 100.
Each character takes 1 byte. So total number of bits needed = 800.
After Huffman Coding, the characters can be represented with:
f: 0
c: 100
d: 101
a: 1100
b: 1101
e: 111
Total number of bits needed = 224
Hence, number of bits saved = 800 - 224 = 576
See here for complete explanation and algorithm.
这个问题的测验