Acknowledgment
Acknowledgment
It is my pleasure that I acknowledge the assistance I have received from many individuals the
length of the list of those who deserve credit makes it impartial to name individuals.
First of all, I thank the lord of heaven who creates these opportunities for me and the strength
to prepare this assignment next my teacher for encouraging and helped me get confidence to
do this assignment. And also, my thank goes to my families who gave me moral support to
I would also deeply thank other teachers who gave a helpful advice, necessary guidance and
support with high concern for the topic. I own a special recognition to my friends for their
1
Introduction
This idea is basically dependent upon the frequency, i.e. the frequency of the corresponding
character which needs to be compressed, and by that frequency, only Huffman code will be
generated. In case of Huffman coding, the most generated character will get the small code
and least generated character will get the large code. Huffman tree is a specific method of
representing each symbol. This technique produces a code in such a manner that no
codeword is a prefix of some other code word. These codes are called as prefix code.
2
ALGORITHM FOR HUFFMAN CODE
METHOD 1
Begin
define a node with character, frequency, left and right child of the node for Huffman tree.
create a list ‘freq’ to store frequency of each character, initially, all are 0
for each character c in the string do
increase the frequency for character ch in freq list.
done
METHOD 2
Huffman (C)
1. n=|C|
2. Q ← C
3. for i=1 to n-1
4. do
5. z= allocate-Node ()
6. x= left[z]=Extract-Min(Q)
7. y= right[z] =Extract-Min(Q)
8. f [z]=f[x]+f[y]
3
9. Insert (Q, z)
10. return Extract-Min (Q)