160 likes | 294 Views
Huffman codes. Overview. an effective technique for compressing data typical savings are 20% to 90%. Technique. greedy algorithm use a table of frequencies of occurence of each character to build up and optimal way of representing each character as a binary string. Definition.
E N D
Overview • an effective technique for compressing data • typical savings are 20% to 90%
Technique • greedy algorithm • use a table of frequencies of occurence of each character to build up and optimal way of representing each character as a binary string
Definition • binary character code: each character is represented by a unique binary string • fixed-length code: each character is represented by a fixed number of binary • variable-length code: each character is represented by any numbers of binary
Definition (cont.) • prefix codes: codes in which no codeword is also a prefix of some other codeword
Example • From the following information, • create a Huffman coding tree
Solution • First, sort the frequencies in the frequency queue (ascending order) • Second, pair two of the least values frequencies • Re-sort the frequency queue • Repeat second step until all frequencies have been combined into a complete Huffman tree • Assign code
Solution b:5 10 f:5 c:14 d:16 e:20 a:40 b:5 f:5
Solution 10 24 c:14 d:16 e:20 a:40 10 c:14 b:5 f:5 b:5 f:5
Solution 24 d:16 e:20 d:16 24 e:20 a:40 10 c:14 10 c:14 b:5 f:5 b:5 f:5
Solution 36 d:16 e:20 24 a:40 d:16 e:20 10 c:14 b:5 f:5
36 36 24 24 d:16 d:16 e:20 e:20 10 10 c:14 c:14 b:5 b:5 f:5 f:5 Solution a:40
36 36 24 24 d:16 d:16 e:20 e:20 10 10 c:14 c:14 b:5 b:5 f:5 f:5 Solution 60 a:40
36 36 60 60 24 24 d:16 d:16 e:20 e:20 10 10 c:14 c:14 b:5 b:5 f:5 f:5 Solution 100 a:40 a:40
36 60 24 d:16 e:20 10 c:14 b:5 f:5 Solution 100 0 1 a:40 1 0 0 1 0 1 1 0
Result • From the following information, • We got the following Huffman code