Professional Documents
Culture Documents
Huffman Coding
Huffman Coding
Huffman Coding is generally useful to compress the data in which there are
frequently occurring characters.
There are two ways we can follow to reduce message using Huffman coding
and those are:
Here we have total 20 characters. We know that, all the characters are
represented with their ASCII codes which are 8bit code.
If we take a close look to our message then we can see we only have 5 unique
characters on that message. So, we don’t need 8 bit ASCII to represent those
characters. We can easily represent those characters by using only 3 bit code
(23 =8) which is 0-7. 8 bit character is used to represent all 256 characters.
A 6 000
B 6 001
C 3 010
D 2 011
E 3 100
Now, our message size is 20*3=60 bits
A 6 000
B 6 001
C 3 010
D 2 011
E 3 100
5*8=40 3*5=15
40+15=55
Now, our message size is 20*3=60 bits + table size is 55 bits =115 bits
So, we easily reduce the size of our message by the help of fixed length code.
Variable Length Code:
Huffman code technique tells us that, we can reduce message size more by
using variable length code.
A 6
B 6
C 3
D 2
E 3
A 6 11
B 6 10
C 3 00
D 2 010
E 3 011
Code is now easily calculated from decision tree. We can understand that
codes are variable length. Character which has higher frequency has lower
code in bits and character with lower frequency is higher in bits.
A 6 11 6*2=12
B 6 10 6*2=12
C 3 00 3*2=6
D 2 010 2*3=6
E 3 011 3*3=9