SlideShare a Scribd company logo
3
Most read
12
Most read
Huffman Algorithm
and its
Applications
by Ekansh Agarwal(J001)
Contents 1. Introduction
2. Steps/Algorithm to build Huffman tree
3. (Example) Building Huffman tree with
sample inputs
4. Steps/Algorithm for traversing the Huffman
tree
5. Real Life applications of Algorithm
6. Advantages/Disadvantages
7. References
2
Introduction 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. The variable-
length codes assigned to input characters are Prefix
Codes, means the codes (bit sequences) are assigned in
such a way that the code assigned to one character is not
the prefix of code assigned to any other character. This is
how Huffman Coding makes sure that there is no
ambiguity when decoding the generated bit stream.
3
Introduction 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.
4
Steps/Algorithm
to build Huffman
table
1. Create a leaf node for each unique character and build a min heap
of all leaf nodes (Min Heap is used as a priority queue. The value
of frequency field is used to compare two nodes in min heap.
Initially, the least frequent character is at root)
2. Extract two nodes with the minimum frequency from the min
heap.
3. Create a new internal node with a frequency equal to the sum of
the two nodes frequencies. Make the first extracted node as its left
child and the other extracted node as its right child. Add this node
to the min heap.
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.
5
Example-: Sample Data
6
Step A Create a leaf node for each character and build a min heap using all the nodes (The frequency value is used to
compare two nodes in min heap)
Resulted
Leaf Nodes
for each
Character
7
Step B- Repeat
the following
steps till heap
has more than
one nodes
Step 1: Extract two
nodes, say x and y,
with minimum
frequency from the
heap
Step 2 : Create a new
internal node z with x
as its left child and y
as its right child. Also
frequency(z)=
frequency(x)+frequen
cy(y)
Step 3: Add z to min
heap. Then Extract
and Combine node
u with an internal
node having 4 as
the frequency then
add the new
internal node to
priority queue
8
Step B- Repeat
the following
steps till heap
has more than
one nodes
Step 4: Extract and
combine node a
with an internal
node having 8 as
the frequency then
add the new
internal node to
priority queue
Step 5: Extract and
Combine nodes i
and s then add the
new internal node
to priority queue-
Step 6: Extract and
Combine nodes i
and s then add the
new internal node
to priority queue-
9
Step B- Repeat
the following
steps till heap
has more than
one nodes
Step 7: Extract and
Combine node e
with an internal
node having 18 as
the frequency then
add the new
internal node to
priority queue-
Step 8: Finally, Extract
and Combine internal
nodes having 25 and
33 as the frequency
then add the new
internal node to
priority queue-
10
Steps to
traversing
Huffman Tree
1. Create an auxiliary array
2. Traverse the tree starting from root node
3. Add 0 to array while traversing the left
child and add 1 to array while traversing
the right child
4. Print the array elements whenever a leaf
node is found
11
Need for
traversing
Huffman Tree
Suppose the string “staeiout” needs to be
transmitted from computer A (sender) to
computer B (receiver) across a network. Using
concepts of Huffman encoding, the string gets
encoded to binary codes at sender address
12
Conclusion of all the steps used to demonstrated in above sample example
12
11
10
9
8
7
6
5
4
3
2
1
Create leaf nodes for
all the characters and
add them to the min
heap.
Extract two nodes, say
x and y, with minimum
frequency from the
heap Add z to min heap
Since internal node
with frequency 58 is
the only node in the
queue, it becomes the
root of Huffman tree.
Create an auxiliary
array
Add 0 to array while
traversing the left child
and add 1 to array
while traversing the
right child
Repeat the following
steps till heap has
more than one nodes
Create a new internal
node z with x as its left
child and y as its right
child. Also
frequency(z)=
frequency(x)+frequenc
y(y)
Extract and Combine
node u with an internal
node having 4 as the
frequency
Last node in the heap
is the root of Huffman
tree
Traverse the tree
starting from root node
Print the array
elements
whenever a leaf
node is found
13
Real-life
Applications of
Huffman Codding
Applications of Huffman Codding-:
◎ Huffman encoding is widely used in compression formats
like GZIP, PKZIP (WinZip) and BZIP2.
◎ Multimedia codecs like JPEG, PNG and MP3 uses Huffman
encoding (to be more precise the prefix codes)
◎ Huffman encoding still dominates the compression industry since
newer arithmetic and range coding schemes are avoided due to
their patent issues.
14
Advantages of Huffman Encoding-
◎ This encoding scheme results in saving lot of storage space,
since the binary codes generated are variable in length
◎ It generates shorter binary codes for encoding
symbols/characters that appear more frequently in the input
string
◎ The binary codes generated are prefix-free
Advantages/
Disadvantages
15
Disadvantages of Huffman Encoding-
◎ Lossless data encoding schemes, like Huffman encoding, achieve a
lower compression ratio compared to lossy encoding techniques. Thus,
lossless techniques like Huffman encoding are suitable only for
encoding text and program files and are unsuitable for encoding digital
images.
◎ Huffman encoding is a relatively slower process since it uses two
passes- one for building the statistical model and another for encoding.
Thus, the lossless techniques that use Huffman encoding are
considerably slower than others.
◎ Since length of all the binary codes is different, it becomes difficult for
the decoding software to detect whether the encoded data is corrupt.
This can result in an incorrect decoding and subsequently, a wrong
output.
Advantages/
Disadvantages
16
References 1. Bao Ergude;Li Weisheng;Fan A Study and Implementation of
the Huffman Algorithm Based on Condensed Huffman Table
2. Rabia Arshad;Adeel Saleem;Danista Khan Performance
comparison of Huffman Coding and double Huffman Coding
3. Hoang-Anh Pham;Van-Hieu 2010 Fifth IEEE International
Symposium on Electronic Design, Test & Applications An
Adaptive Huffman Decoding Algorithm for MP3 Decoder
4. Studytonight Huffman Coding Algorithm
5. GeekforGeeks Application of Huffman algorithm
17

More Related Content

What's hot (20)

PPTX
3. line coding( bipolar, multilevel, multitransition)
MdFazleRabbi18
 
PPT
Assembly Language Lecture 4
Motaz Saad
 
PPT
Lecture 08
Sehrish Rafiq
 
PDF
Physical Layer Numericals - Data Communication & Networking
Drishti Bhalla
 
PDF
Data compression huffman coding algoritham
Rahul Khanwani
 
PPTX
Computer architecture data representation
Anil Pokhrel
 
PPTX
Huffman's algorithm in Data Structure
Vrushali Dhanokar
 
PPT
Error detection and correction
Maria Akther
 
PDF
Stop and-wait protocol
Venkata Sreeram
 
PDF
Coding
Dayal Sati
 
PPTX
Huffman coding || Huffman Tree
SatishKumarInumarthi
 
PDF
Lexical Analysis - Compiler design
Aman Sharma
 
PPT
Type Checking(Compiler Design) #ShareThisIfYouLike
United International University
 
PPT
Complements
Sudheesh S Madhav
 
PPT
Axi protocol
Azad Mishra
 
PPTX
4. block coding
MdFazleRabbi18
 
PDF
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
 
PDF
Shannon-Fano algorithm
MANISH T I
 
PPTX
Harvard architecture
Gichelle Amon
 
3. line coding( bipolar, multilevel, multitransition)
MdFazleRabbi18
 
Assembly Language Lecture 4
Motaz Saad
 
Lecture 08
Sehrish Rafiq
 
Physical Layer Numericals - Data Communication & Networking
Drishti Bhalla
 
Data compression huffman coding algoritham
Rahul Khanwani
 
Computer architecture data representation
Anil Pokhrel
 
Huffman's algorithm in Data Structure
Vrushali Dhanokar
 
Error detection and correction
Maria Akther
 
Stop and-wait protocol
Venkata Sreeram
 
Coding
Dayal Sati
 
Huffman coding || Huffman Tree
SatishKumarInumarthi
 
Lexical Analysis - Compiler design
Aman Sharma
 
Type Checking(Compiler Design) #ShareThisIfYouLike
United International University
 
Complements
Sudheesh S Madhav
 
Axi protocol
Azad Mishra
 
4. block coding
MdFazleRabbi18
 
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
 
Shannon-Fano algorithm
MANISH T I
 
Harvard architecture
Gichelle Amon
 

Similar to Huffman Algorithm and its Application by Ekansh Agarwal (20)

PPTX
DAA PPT.pptx
SintooChauhan6
 
PPTX
t.pptx hd gsd unduf jdsnfijnfi bndsfuu ubfuh
chouhangulbadansing
 
PPTX
Huffman coding || Huffman Tree
Gurunadh Guru
 
PDF
Huffman Encoding Algorithm - Concepts and Example
MaryJacob24
 
PPTX
Huffman Codes
Md. Shafiuzzaman Hira
 
PDF
DSA Presentetion Huffman tree.pdf
GaneshPawar819187
 
PDF
Huffman
keerthi vasan
 
PDF
Huffman
keerthi vasan
 
PDF
Adaptive huffman coding
Burqaa Hundeessaa
 
PPT
Greedy Algorithms Huffman Coding.ppt
Ruchika Sinha
 
PDF
Implementation of Lossless Compression Algorithms for Text Data
BRNSSPublicationHubI
 
PPTX
Huffman tree
Al-amin Hossain
 
PPT
hufman coding for compression algorithm.ppt
alvishi254
 
PPT
hufman code presentation and how to compress data using hufman code
ssuser6059cf
 
PPT
compression & huffman coder problem .ppt
pradeepkumar465177
 
PPTX
5c. huffman coding using greedy technique.pptx
Suma Raj
 
PPT
Hufman coding basic
radthees
 
DOCX
Huffman Coding is a technique of compressing data
Kumari99
 
PPTX
Huffman ppt
ALexHunter69
 
PDF
Huffman Text Compression Technique
Universitas Pembangunan Panca Budi
 
DAA PPT.pptx
SintooChauhan6
 
t.pptx hd gsd unduf jdsnfijnfi bndsfuu ubfuh
chouhangulbadansing
 
Huffman coding || Huffman Tree
Gurunadh Guru
 
Huffman Encoding Algorithm - Concepts and Example
MaryJacob24
 
Huffman Codes
Md. Shafiuzzaman Hira
 
DSA Presentetion Huffman tree.pdf
GaneshPawar819187
 
Huffman
keerthi vasan
 
Huffman
keerthi vasan
 
Adaptive huffman coding
Burqaa Hundeessaa
 
Greedy Algorithms Huffman Coding.ppt
Ruchika Sinha
 
Implementation of Lossless Compression Algorithms for Text Data
BRNSSPublicationHubI
 
Huffman tree
Al-amin Hossain
 
hufman coding for compression algorithm.ppt
alvishi254
 
hufman code presentation and how to compress data using hufman code
ssuser6059cf
 
compression & huffman coder problem .ppt
pradeepkumar465177
 
5c. huffman coding using greedy technique.pptx
Suma Raj
 
Hufman coding basic
radthees
 
Huffman Coding is a technique of compressing data
Kumari99
 
Huffman ppt
ALexHunter69
 
Huffman Text Compression Technique
Universitas Pembangunan Panca Budi
 
Ad

More from Ekansh Agarwal (20)

PPTX
Fundamentals of accounting with questionaire
Ekansh Agarwal
 
PPT
Introduction to Operation Management by EA
Ekansh Agarwal
 
PPTX
Licensing framework for establishing Satellite Earth Station Gateway
Ekansh Agarwal
 
PPTX
Applicability of MIMO in satellite communication by Ekansh Agarwal
Ekansh Agarwal
 
PPTX
A study on RPA implementation in network management process and its applicati...
Ekansh Agarwal
 
PPTX
Business - Model Canvas by Ekansh Agarwal
Ekansh Agarwal
 
PPTX
Maruti Suzuki- Making Automobile Accessible
Ekansh Agarwal
 
PPTX
An Empirical Analysis of Disney+ Hotstar's Market-Specific Strategies Across ...
Ekansh Agarwal
 
PPTX
Organizational Culture
Ekansh Agarwal
 
PPTX
Business market communication research on HCL technologies India
Ekansh Agarwal
 
PPTX
Online File storage system using RSA and 3DES
Ekansh Agarwal
 
PPTX
Data transmission using hybrid cryptography with code
Ekansh Agarwal
 
PPTX
Email Etiquettes
Ekansh Agarwal
 
PPTX
Digital Marketing
Ekansh Agarwal
 
PPTX
Trademark logo submission
Ekansh Agarwal
 
PPTX
Pernod Ricard India Private Limited v. Frost Falcon Distilleries Limited by E...
Ekansh Agarwal
 
PPTX
Medical appplication of Fiber optics
Ekansh Agarwal
 
PPTX
A study on Robotic Process Automation in network management process and its a...
Ekansh Agarwal
 
PPTX
Presentation SIM CARD (GSM)
Ekansh Agarwal
 
PPTX
Superstitions in India
Ekansh Agarwal
 
Fundamentals of accounting with questionaire
Ekansh Agarwal
 
Introduction to Operation Management by EA
Ekansh Agarwal
 
Licensing framework for establishing Satellite Earth Station Gateway
Ekansh Agarwal
 
Applicability of MIMO in satellite communication by Ekansh Agarwal
Ekansh Agarwal
 
A study on RPA implementation in network management process and its applicati...
Ekansh Agarwal
 
Business - Model Canvas by Ekansh Agarwal
Ekansh Agarwal
 
Maruti Suzuki- Making Automobile Accessible
Ekansh Agarwal
 
An Empirical Analysis of Disney+ Hotstar's Market-Specific Strategies Across ...
Ekansh Agarwal
 
Organizational Culture
Ekansh Agarwal
 
Business market communication research on HCL technologies India
Ekansh Agarwal
 
Online File storage system using RSA and 3DES
Ekansh Agarwal
 
Data transmission using hybrid cryptography with code
Ekansh Agarwal
 
Email Etiquettes
Ekansh Agarwal
 
Digital Marketing
Ekansh Agarwal
 
Trademark logo submission
Ekansh Agarwal
 
Pernod Ricard India Private Limited v. Frost Falcon Distilleries Limited by E...
Ekansh Agarwal
 
Medical appplication of Fiber optics
Ekansh Agarwal
 
A study on Robotic Process Automation in network management process and its a...
Ekansh Agarwal
 
Presentation SIM CARD (GSM)
Ekansh Agarwal
 
Superstitions in India
Ekansh Agarwal
 
Ad

Recently uploaded (20)

PPTX
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
PDF
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
PPT
Carmon_Remote Sensing GIS by Mahesh kumar
DhananjayM6
 
PPTX
Introduction to Design of Machine Elements
PradeepKumarS27
 
PDF
Set Relation Function Practice session 24.05.2025.pdf
DrStephenStrange4
 
PDF
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
PDF
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
PDF
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
PDF
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
PPTX
Green Building & Energy Conservation ppt
Sagar Sarangi
 
PPTX
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PPTX
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
PPTX
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
PDF
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
PPTX
Hashing Introduction , hash functions and techniques
sailajam21
 
PPTX
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
PPTX
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
PDF
Zilliz Cloud Demo for performance and scale
Zilliz
 
PPTX
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
Carmon_Remote Sensing GIS by Mahesh kumar
DhananjayM6
 
Introduction to Design of Machine Elements
PradeepKumarS27
 
Set Relation Function Practice session 24.05.2025.pdf
DrStephenStrange4
 
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
Green Building & Energy Conservation ppt
Sagar Sarangi
 
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
Hashing Introduction , hash functions and techniques
sailajam21
 
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
Zilliz Cloud Demo for performance and scale
Zilliz
 
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 

Huffman Algorithm and its Application by Ekansh Agarwal

  • 2. Contents 1. Introduction 2. Steps/Algorithm to build Huffman tree 3. (Example) Building Huffman tree with sample inputs 4. Steps/Algorithm for traversing the Huffman tree 5. Real Life applications of Algorithm 6. Advantages/Disadvantages 7. References 2
  • 3. Introduction 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. The variable- length codes assigned to input characters are Prefix Codes, means the codes (bit sequences) are assigned in such a way that the code assigned to one character is not the prefix of code assigned to any other character. This is how Huffman Coding makes sure that there is no ambiguity when decoding the generated bit stream. 3
  • 4. Introduction 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. 4
  • 5. Steps/Algorithm to build Huffman table 1. Create a leaf node for each unique character and build a min heap of all leaf nodes (Min Heap is used as a priority queue. The value of frequency field is used to compare two nodes in min heap. Initially, the least frequent character is at root) 2. Extract two nodes with the minimum frequency from the min heap. 3. Create a new internal node with a frequency equal to the sum of the two nodes frequencies. Make the first extracted node as its left child and the other extracted node as its right child. Add this node to the min heap. 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. 5
  • 7. Step A Create a leaf node for each character and build a min heap using all the nodes (The frequency value is used to compare two nodes in min heap) Resulted Leaf Nodes for each Character 7
  • 8. Step B- Repeat the following steps till heap has more than one nodes Step 1: Extract two nodes, say x and y, with minimum frequency from the heap Step 2 : Create a new internal node z with x as its left child and y as its right child. Also frequency(z)= frequency(x)+frequen cy(y) Step 3: Add z to min heap. Then Extract and Combine node u with an internal node having 4 as the frequency then add the new internal node to priority queue 8
  • 9. Step B- Repeat the following steps till heap has more than one nodes Step 4: Extract and combine node a with an internal node having 8 as the frequency then add the new internal node to priority queue Step 5: Extract and Combine nodes i and s then add the new internal node to priority queue- Step 6: Extract and Combine nodes i and s then add the new internal node to priority queue- 9
  • 10. Step B- Repeat the following steps till heap has more than one nodes Step 7: Extract and Combine node e with an internal node having 18 as the frequency then add the new internal node to priority queue- Step 8: Finally, Extract and Combine internal nodes having 25 and 33 as the frequency then add the new internal node to priority queue- 10
  • 11. Steps to traversing Huffman Tree 1. Create an auxiliary array 2. Traverse the tree starting from root node 3. Add 0 to array while traversing the left child and add 1 to array while traversing the right child 4. Print the array elements whenever a leaf node is found 11
  • 12. Need for traversing Huffman Tree Suppose the string “staeiout” needs to be transmitted from computer A (sender) to computer B (receiver) across a network. Using concepts of Huffman encoding, the string gets encoded to binary codes at sender address 12
  • 13. Conclusion of all the steps used to demonstrated in above sample example 12 11 10 9 8 7 6 5 4 3 2 1 Create leaf nodes for all the characters and add them to the min heap. Extract two nodes, say x and y, with minimum frequency from the heap Add z to min heap Since internal node with frequency 58 is the only node in the queue, it becomes the root of Huffman tree. Create an auxiliary array Add 0 to array while traversing the left child and add 1 to array while traversing the right child Repeat the following steps till heap has more than one nodes Create a new internal node z with x as its left child and y as its right child. Also frequency(z)= frequency(x)+frequenc y(y) Extract and Combine node u with an internal node having 4 as the frequency Last node in the heap is the root of Huffman tree Traverse the tree starting from root node Print the array elements whenever a leaf node is found 13
  • 14. Real-life Applications of Huffman Codding Applications of Huffman Codding-: ◎ Huffman encoding is widely used in compression formats like GZIP, PKZIP (WinZip) and BZIP2. ◎ Multimedia codecs like JPEG, PNG and MP3 uses Huffman encoding (to be more precise the prefix codes) ◎ Huffman encoding still dominates the compression industry since newer arithmetic and range coding schemes are avoided due to their patent issues. 14
  • 15. Advantages of Huffman Encoding- ◎ This encoding scheme results in saving lot of storage space, since the binary codes generated are variable in length ◎ It generates shorter binary codes for encoding symbols/characters that appear more frequently in the input string ◎ The binary codes generated are prefix-free Advantages/ Disadvantages 15
  • 16. Disadvantages of Huffman Encoding- ◎ Lossless data encoding schemes, like Huffman encoding, achieve a lower compression ratio compared to lossy encoding techniques. Thus, lossless techniques like Huffman encoding are suitable only for encoding text and program files and are unsuitable for encoding digital images. ◎ Huffman encoding is a relatively slower process since it uses two passes- one for building the statistical model and another for encoding. Thus, the lossless techniques that use Huffman encoding are considerably slower than others. ◎ Since length of all the binary codes is different, it becomes difficult for the decoding software to detect whether the encoded data is corrupt. This can result in an incorrect decoding and subsequently, a wrong output. Advantages/ Disadvantages 16
  • 17. References 1. Bao Ergude;Li Weisheng;Fan A Study and Implementation of the Huffman Algorithm Based on Condensed Huffman Table 2. Rabia Arshad;Adeel Saleem;Danista Khan Performance comparison of Huffman Coding and double Huffman Coding 3. Hoang-Anh Pham;Van-Hieu 2010 Fifth IEEE International Symposium on Electronic Design, Test & Applications An Adaptive Huffman Decoding Algorithm for MP3 Decoder 4. Studytonight Huffman Coding Algorithm 5. GeekforGeeks Application of Huffman algorithm 17