Huffman codes

   

Huffman codes  compress data very effectively: savings of 20% to 90% are typical, depending on the characteristics of the data being compressed. 

  功能:

  huffman 编码能有效的压缩数据。

  如何解决:

  Huffman’s greedy algorithm uses a table giving how often each character occurs (i.e., its frequency) to build up an optimal way of representing each character as a binary string. 

  

  we interpret the  binary codeword for a character as the simple path from the root to that character ,where 0 means go to the left child and 1 means  go to the right child .

  

we interpret the  binary codeword

for a character as the simple path from the root to that character ,where 0 means go to the left child and 1 means  go to the right child .

 

Note that these are not binary search trees, since the leaves need not appear in sorted order and internal nodes do not contain character keys.

an optimal code for a  file is always represented by a fully binary tree ,in which every nonleaf has two children .

 

the tree for an optimal prefix code has exactly |C| leaves ,one for each letter of the alphabet ,ash exactly |c|-1interanl nodes .

 

 

 

 

what is the meaning 

when we merge two objects ,the result is a new object whose frequency is the sum of the frequencies of the two object that were merged . 

 

   

posted @ 2015-04-18 21:29  巴山夜雨1989  阅读(165)  评论(0编辑  收藏  举报