(6.7.1)--ch6-13HuffmanCoding0821.pdf
《(6.7.1)--ch6-13HuffmanCoding0821.pdf》由会员分享,可在线阅读,更多相关《(6.7.1)--ch6-13HuffmanCoding0821.pdf(16页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Data Structures and Algorithms 26.7 Huffman Coding The Huffman tree can be used to obtain the code with the shortest average length.Therefore,the Huffman tree has a wide range of applications in information transmission and data compression.In practical applications such as information transmission,
2、the characters appearing in the text need to be binary coded.After transmission,the binary code must be translated into the original characters.This is a typical coding and decoding problem.(1)The code can be decoded uniquely.(2)The code length should be as short as possible.Data Structures and Algo
3、rithmsData Structures and AlgorithmsChapter 6 Trees and Binary TreesIn the design of coding,two principles are usually followed:3Data Structures and AlgorithmsData Structures and AlgorithmsChapter 6 Trees and Binary Trees6.7 Huffman Coding1.Related conceptsThe codes with the shortest average length
4、are generally unequal length codes.Equal length coding:The code length of each character is the same.Unequal length coding:Characters with high frequency of use have short codes,and characters with low frequency of use have relatively long codes.4Data Structures and AlgorithmsData Structures and Alg
5、orithmsChapter 6 Trees and Binary Trees6.7 Huffman CodingExample:The character set to be encoded is:A、B、CEqual length coding(two bits per character)A:00,B:01,C:10Unequal length coding can be designed as:A:0,B:11,C:10If the text to be encoded is:AAABAC,the coding results are:Equal length coding:00000
6、0010010,total length is 12 bits.Unequal length coding:00011010,total length is 8 bits.5Data Structures and AlgorithmsData Structures and AlgorithmsChapter 6 Trees and Binary Trees6.7 Huffman CodingUnequal length coding has the problem that it cannot be effectively recognized when decoding!Example:Th
7、e character set to be encoded is:A、B、C、DUnequal length coding is:A:0 B:1 C:00 D:01If the text to be encoded is:ABACAD,the encoding result is:01000001The issue is:01000001 can be decoded as ABACAD01000001 can also be decoded as DCCD01000001 can also be decoded as ABAAAAAB6Data Structures and Algorith
8、msData Structures and AlgorithmsChapter 6 Trees and Binary Trees6.7 Huffman CodingFor unequal length coding,in For unequal length coding,in order to effectively identify order to effectively identify the codes without adding the codes without adding delimiters,the codes should be delimiters,the code
9、s should be prefix codesprefix codes.7Data Structures and AlgorithmsData Structures and AlgorithmsChapter 6 Trees and Binary Trees6.7 Huffman CodingPrefix encoding:The encoding of any character is not a prefix of another character encoding in the same character set.In the previous example,the code i
10、s designed as A:0,B:1,C:00,D:01,which does not comform to the rules of prefix encoding and cannot be effectively identified!How to design?The The prefix code prefix code that has the shortest average length that has the shortest average length and can be effectively identified.and can be effectively
11、 identified.Use the Huffman tree!Use the Huffman tree!8Data Structures and AlgorithmsData Structures and AlgorithmsChapter 6 Trees and Binary Trees6.7 Huffman Coding The Huffman tree is a binary tree with the smallest weighted path length value.Its characteristics are:The idea of designing coding wi
12、th Huffman tree is:Each character to be encoded corresponds to a leaf node;The frequency of utilization of each character corresponds to the weight of the leaf;The encoding of each character corresponds to the path from root to leaf.The greater the weight of the leaf node,the closer to the root!The
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 6.7 ch6 13 HuffmanCoding0821
限制150内