Date post: | 29-Dec-2015 |
Category: |
Documents |
Upload: | cory-davidson |
View: | 214 times |
Download: | 0 times |
Fixed length codea: 00 b: 01 c: 11
Given this code, if our file isababcbbbc
our encoding is000100011101010111
Variable length code:a: 01 b: 1 c:00
our encoding is0110110011100
Prefix Codes
In a prefix code no codeword for one character constitutes the beginning of the codeword for another character
a: 0b: 10c: 11
Suppose our character set is {a,b,c,d,e,f} and each character appears in the file the number of times indicated in The following table. This table also shows three different codes we could use to encode the file.
Character
Frequency
C1(Fixed-length)
C2(Variable-length)
C3(Huffman)
a 16 000 001 11
b 5 001 00000 0001
c 12 010 0001 001
d 17 011 01 10
e 10 100 00001 0000
f 25 101 1 01
Huffman's Algorithm
for (i = 1; i < = n-1; i++) {
remove (Q, p); remove (Q, q); r = new nodetype; r.left = p; r.right = q; r.frequency = p.frequency + q.frequency; insert (Q, r);
}