Huffman’s Algorithm
What is Huffman’s Algorithm?
 Huffman’s algorithm is a method for building
an extended binary tree with minimum weighted path
length from a set of given weights
It is technique for compressing data.
What is Huffman’s Algorithm?

Huffman coding is a lossless data compression
algorithm. The idea is to assign variable-length
codes to input characters, lengths of the
assigned codes are based on the frequencies of
corresponding characters.
The most frequent character gets the smallest
code and the least frequent character gets the
largest code.
Tree Construction Rules
• There are mainly two major parts in Huffman Coding
1) Build a Huffman Tree from input characters.
2) Traverse the Huffman Tree and assign codes to
characters

•
1.
2.
3.

Steps to build Huffman Tree
Create a leaf node for each unique character
Extract two nodes with the minimum frequency
Create a new internal node with frequency equal to the
sum of the two nodes frequencies.
4. 4. Repeat steps#2 and #3 until the heap contains only
one node. The remaining node is the root node and the
tree is complete
Huffman Tree Construction
A

3

C

E

H

I

5

8

2

7
Huffman Tree Construction
A

H

3

2

5

C
5

E
8

I
7
Huffman Tree Construction
E

H

3

2
C
5

5

10

I

8

A

7
Huffman Tree Construction
E

H

3

I

8

A

7

2
C
15
5

5

10
Huffman Tree Construction
A

H

3

2

1
5

C

E

I

5

0

8

7

0

1

1

0
15

10
0

1
25

E
I
C
A
H

=
=
=
=
=

00
01
10
111
110
Huffman's Alforithm

Huffman's Alforithm