SlideShare a Scribd company logo
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
Ad

More Related Content

What's hot (20)

Analysis of the source program
Analysis of the source programAnalysis of the source program
Analysis of the source program
Huawei Technologies
 
SHA 1 Algorithm
SHA 1 AlgorithmSHA 1 Algorithm
SHA 1 Algorithm
Shiva RamDam
 
Huffman tree
Huffman tree Huffman tree
Huffman tree
Al-amin Hossain
 
Error Detection and Correction presentation
Error Detection and Correction presentation Error Detection and Correction presentation
Error Detection and Correction presentation
Badrul Alam
 
SHA 1 Algorithm.ppt
SHA 1 Algorithm.pptSHA 1 Algorithm.ppt
SHA 1 Algorithm.ppt
Rajapriya82
 
Computer Network notes (handwritten) UNIT 1
Computer Network notes (handwritten) UNIT 1Computer Network notes (handwritten) UNIT 1
Computer Network notes (handwritten) UNIT 1
NANDINI SHARMA
 
Parallel processing and pipelining
Parallel processing and pipeliningParallel processing and pipelining
Parallel processing and pipelining
mahesh kumar prajapat
 
chapter 7 Logic, shift and rotate instructions
chapter 7 Logic, shift and rotate instructionschapter 7 Logic, shift and rotate instructions
chapter 7 Logic, shift and rotate instructions
warda aziz
 
Huffman Encoding Pr
Huffman Encoding PrHuffman Encoding Pr
Huffman Encoding Pr
anithabalaprabhu
 
Huffman Coding Algorithm Presentation
Huffman Coding Algorithm PresentationHuffman Coding Algorithm Presentation
Huffman Coding Algorithm Presentation
Akm Monir
 
Elgamal & schnorr digital signature scheme copy
Elgamal & schnorr digital signature scheme   copyElgamal & schnorr digital signature scheme   copy
Elgamal & schnorr digital signature scheme copy
North Cap University (NCU) Formely ITM University
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
Akhil Kaushik
 
File system structure
File system structureFile system structure
File system structure
sangrampatil81
 
Pipeline processing and space time diagram
Pipeline processing and space time diagramPipeline processing and space time diagram
Pipeline processing and space time diagram
Rahul Sharma
 
Count-Distinct Problem
Count-Distinct ProblemCount-Distinct Problem
Count-Distinct Problem
Kai Zhang
 
Huffman and Arithmetic coding - Performance analysis
Huffman and Arithmetic coding - Performance analysisHuffman and Arithmetic coding - Performance analysis
Huffman and Arithmetic coding - Performance analysis
Ramakant Soni
 
Decimal adder
Decimal adderDecimal adder
Decimal adder
Syed Saeed
 
Chapter 6 Flow control Instructions
Chapter 6 Flow control InstructionsChapter 6 Flow control Instructions
Chapter 6 Flow control Instructions
warda aziz
 
Flag Registers (Assembly Language)
Flag Registers (Assembly Language)Flag Registers (Assembly Language)
Flag Registers (Assembly Language)
Anwar Hasan Shuvo
 
Modern block cipher
Modern block cipherModern block cipher
Modern block cipher
Udit Mishra
 
Error Detection and Correction presentation
Error Detection and Correction presentation Error Detection and Correction presentation
Error Detection and Correction presentation
Badrul Alam
 
SHA 1 Algorithm.ppt
SHA 1 Algorithm.pptSHA 1 Algorithm.ppt
SHA 1 Algorithm.ppt
Rajapriya82
 
Computer Network notes (handwritten) UNIT 1
Computer Network notes (handwritten) UNIT 1Computer Network notes (handwritten) UNIT 1
Computer Network notes (handwritten) UNIT 1
NANDINI SHARMA
 
chapter 7 Logic, shift and rotate instructions
chapter 7 Logic, shift and rotate instructionschapter 7 Logic, shift and rotate instructions
chapter 7 Logic, shift and rotate instructions
warda aziz
 
Huffman Coding Algorithm Presentation
Huffman Coding Algorithm PresentationHuffman Coding Algorithm Presentation
Huffman Coding Algorithm Presentation
Akm Monir
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
Akhil Kaushik
 
Pipeline processing and space time diagram
Pipeline processing and space time diagramPipeline processing and space time diagram
Pipeline processing and space time diagram
Rahul Sharma
 
Count-Distinct Problem
Count-Distinct ProblemCount-Distinct Problem
Count-Distinct Problem
Kai Zhang
 
Huffman and Arithmetic coding - Performance analysis
Huffman and Arithmetic coding - Performance analysisHuffman and Arithmetic coding - Performance analysis
Huffman and Arithmetic coding - Performance analysis
Ramakant Soni
 
Chapter 6 Flow control Instructions
Chapter 6 Flow control InstructionsChapter 6 Flow control Instructions
Chapter 6 Flow control Instructions
warda aziz
 
Flag Registers (Assembly Language)
Flag Registers (Assembly Language)Flag Registers (Assembly Language)
Flag Registers (Assembly Language)
Anwar Hasan Shuvo
 
Modern block cipher
Modern block cipherModern block cipher
Modern block cipher
Udit Mishra
 

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

Huffman's algorithm in Data Structure
 Huffman's algorithm in Data Structure Huffman's algorithm in Data Structure
Huffman's algorithm in Data Structure
Vrushali Dhanokar
 
Huffman ppt
Huffman ppt Huffman ppt
Huffman ppt
ALexHunter69
 
Ppt of discrete structure copy - copy - copy
Ppt of discrete structure   copy - copy - copyPpt of discrete structure   copy - copy - copy
Ppt of discrete structure copy - copy - copy
MRA7860
 
INSTRUCTIONS For this assignment you will be generating all code on y.pdf
 INSTRUCTIONS For this assignment you will be generating all code on y.pdf INSTRUCTIONS For this assignment you will be generating all code on y.pdf
INSTRUCTIONS For this assignment you will be generating all code on y.pdf
adayarboot
 
Lossless
LosslessLossless
Lossless
anithabalaprabhu
 
Lossless
LosslessLossless
Lossless
Vishal Suri
 
Digital Communication GRP1 (1).pptx
Digital Communication GRP1 (1).pptxDigital Communication GRP1 (1).pptx
Digital Communication GRP1 (1).pptx
gidati3640
 
Hufman coding basic
Hufman coding basicHufman coding basic
Hufman coding basic
radthees
 
Implementation of Lossless Compression Algorithms for Text Data
Implementation of Lossless Compression Algorithms for Text DataImplementation of Lossless Compression Algorithms for Text Data
Implementation of Lossless Compression Algorithms for Text Data
BRNSSPublicationHubI
 
Huffman.Encodingpptx Variable length coding
Huffman.Encodingpptx Variable length codingHuffman.Encodingpptx Variable length coding
Huffman.Encodingpptx Variable length coding
zeeshanmubeen1
 
Text compression
Text compressionText compression
Text compression
Sammer Qader
 
Paper id 24201469
Paper id 24201469Paper id 24201469
Paper id 24201469
IJRAT
 
Huffman coding || Huffman Tree
Huffman coding || Huffman TreeHuffman coding || Huffman Tree
Huffman coding || Huffman Tree
SatishKumarInumarthi
 
Data structures' project
Data structures' projectData structures' project
Data structures' project
Behappy Seehappy
 
Huffman Coding is a technique of compressing data
Huffman Coding is a technique of compressing dataHuffman Coding is a technique of compressing data
Huffman Coding is a technique of compressing data
Kumari99
 
Huffman Encoding Algorithm - Concepts and Example
Huffman Encoding Algorithm - Concepts and ExampleHuffman Encoding Algorithm - Concepts and Example
Huffman Encoding Algorithm - Concepts and Example
MaryJacob24
 
Komdat-Kompresi Data
Komdat-Kompresi DataKomdat-Kompresi Data
Komdat-Kompresi Data
mursalinfajri007
 
Sunzip user tool for data reduction using huffman algorithm
Sunzip user tool for data reduction using huffman algorithmSunzip user tool for data reduction using huffman algorithm
Sunzip user tool for data reduction using huffman algorithm
Dr Sandeep Kumar Poonia
 
Adaptive huffman coding
Adaptive huffman codingAdaptive huffman coding
Adaptive huffman coding
Burqaa Hundeessaa
 
Huffman Text Compression Technique
Huffman Text Compression TechniqueHuffman Text Compression Technique
Huffman Text Compression Technique
Universitas Pembangunan Panca Budi
 
Huffman's algorithm in Data Structure
 Huffman's algorithm in Data Structure Huffman's algorithm in Data Structure
Huffman's algorithm in Data Structure
Vrushali Dhanokar
 
Ppt of discrete structure copy - copy - copy
Ppt of discrete structure   copy - copy - copyPpt of discrete structure   copy - copy - copy
Ppt of discrete structure copy - copy - copy
MRA7860
 
INSTRUCTIONS For this assignment you will be generating all code on y.pdf
 INSTRUCTIONS For this assignment you will be generating all code on y.pdf INSTRUCTIONS For this assignment you will be generating all code on y.pdf
INSTRUCTIONS For this assignment you will be generating all code on y.pdf
adayarboot
 
Digital Communication GRP1 (1).pptx
Digital Communication GRP1 (1).pptxDigital Communication GRP1 (1).pptx
Digital Communication GRP1 (1).pptx
gidati3640
 
Hufman coding basic
Hufman coding basicHufman coding basic
Hufman coding basic
radthees
 
Implementation of Lossless Compression Algorithms for Text Data
Implementation of Lossless Compression Algorithms for Text DataImplementation of Lossless Compression Algorithms for Text Data
Implementation of Lossless Compression Algorithms for Text Data
BRNSSPublicationHubI
 
Huffman.Encodingpptx Variable length coding
Huffman.Encodingpptx Variable length codingHuffman.Encodingpptx Variable length coding
Huffman.Encodingpptx Variable length coding
zeeshanmubeen1
 
Paper id 24201469
Paper id 24201469Paper id 24201469
Paper id 24201469
IJRAT
 
Huffman Coding is a technique of compressing data
Huffman Coding is a technique of compressing dataHuffman Coding is a technique of compressing data
Huffman Coding is a technique of compressing data
Kumari99
 
Huffman Encoding Algorithm - Concepts and Example
Huffman Encoding Algorithm - Concepts and ExampleHuffman Encoding Algorithm - Concepts and Example
Huffman Encoding Algorithm - Concepts and Example
MaryJacob24
 
Sunzip user tool for data reduction using huffman algorithm
Sunzip user tool for data reduction using huffman algorithmSunzip user tool for data reduction using huffman algorithm
Sunzip user tool for data reduction using huffman algorithm
Dr Sandeep Kumar Poonia
 
Ad

More from Ekansh Agarwal (20)

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

Recently uploaded (20)

Unleashing the Power of Salesforce Flows &amp_ Slack Integration!.pptx
Unleashing the Power of Salesforce Flows &amp_ Slack Integration!.pptxUnleashing the Power of Salesforce Flows &amp_ Slack Integration!.pptx
Unleashing the Power of Salesforce Flows &amp_ Slack Integration!.pptx
SanjeetMishra29
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
Control Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptxControl Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptx
vvsasane
 
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic AlgorithmDesign Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Journal of Soft Computing in Civil Engineering
 
22PCOAM16 Unit 3 Session 23 Different ways to Combine Classifiers.pptx
22PCOAM16 Unit 3 Session 23  Different ways to Combine Classifiers.pptx22PCOAM16 Unit 3 Session 23  Different ways to Combine Classifiers.pptx
22PCOAM16 Unit 3 Session 23 Different ways to Combine Classifiers.pptx
Guru Nanak Technical Institutions
 
acid base ppt and their specific application in food
acid base ppt and their specific application in foodacid base ppt and their specific application in food
acid base ppt and their specific application in food
Fatehatun Noor
 
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
ijdmsjournal
 
IBAAS 2023 Series_Lecture 8- Dr. Nandi.pdf
IBAAS 2023 Series_Lecture 8- Dr. Nandi.pdfIBAAS 2023 Series_Lecture 8- Dr. Nandi.pdf
IBAAS 2023 Series_Lecture 8- Dr. Nandi.pdf
VigneshPalaniappanM
 
AI Chatbots & Software Development Teams
AI Chatbots & Software Development TeamsAI Chatbots & Software Development Teams
AI Chatbots & Software Development Teams
Joe Krall
 
🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...
🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...
🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...
SanjeetMishra29
 
UNIT 3 Software Engineering (BCS601) EIOV.pdf
UNIT 3 Software Engineering (BCS601) EIOV.pdfUNIT 3 Software Engineering (BCS601) EIOV.pdf
UNIT 3 Software Engineering (BCS601) EIOV.pdf
sikarwaramit089
 
22PCOAM16_MACHINE_LEARNING_UNIT_IV_NOTES_with_QB
22PCOAM16_MACHINE_LEARNING_UNIT_IV_NOTES_with_QB22PCOAM16_MACHINE_LEARNING_UNIT_IV_NOTES_with_QB
22PCOAM16_MACHINE_LEARNING_UNIT_IV_NOTES_with_QB
Guru Nanak Technical Institutions
 
Dahua Smart Cityyyyyyyyyyyyyyyyyy2025.pdf
Dahua Smart Cityyyyyyyyyyyyyyyyyy2025.pdfDahua Smart Cityyyyyyyyyyyyyyyyyy2025.pdf
Dahua Smart Cityyyyyyyyyyyyyyyyyy2025.pdf
PawachMetharattanara
 
Personal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.pptPersonal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.ppt
ganjangbegu579
 
hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .
NABLAS株式会社
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdfLittle Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
gori42199
 
Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025
Antonin Danalet
 
Lecture - 7 Canals of the topic of the civil engineering
Lecture - 7  Canals of the topic of the civil engineeringLecture - 7  Canals of the topic of the civil engineering
Lecture - 7 Canals of the topic of the civil engineering
MJawadkhan1
 
Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control Monthly May 2025Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control
 
Unleashing the Power of Salesforce Flows &amp_ Slack Integration!.pptx
Unleashing the Power of Salesforce Flows &amp_ Slack Integration!.pptxUnleashing the Power of Salesforce Flows &amp_ Slack Integration!.pptx
Unleashing the Power of Salesforce Flows &amp_ Slack Integration!.pptx
SanjeetMishra29
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
Control Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptxControl Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptx
vvsasane
 
22PCOAM16 Unit 3 Session 23 Different ways to Combine Classifiers.pptx
22PCOAM16 Unit 3 Session 23  Different ways to Combine Classifiers.pptx22PCOAM16 Unit 3 Session 23  Different ways to Combine Classifiers.pptx
22PCOAM16 Unit 3 Session 23 Different ways to Combine Classifiers.pptx
Guru Nanak Technical Institutions
 
acid base ppt and their specific application in food
acid base ppt and their specific application in foodacid base ppt and their specific application in food
acid base ppt and their specific application in food
Fatehatun Noor
 
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
ijdmsjournal
 
IBAAS 2023 Series_Lecture 8- Dr. Nandi.pdf
IBAAS 2023 Series_Lecture 8- Dr. Nandi.pdfIBAAS 2023 Series_Lecture 8- Dr. Nandi.pdf
IBAAS 2023 Series_Lecture 8- Dr. Nandi.pdf
VigneshPalaniappanM
 
AI Chatbots & Software Development Teams
AI Chatbots & Software Development TeamsAI Chatbots & Software Development Teams
AI Chatbots & Software Development Teams
Joe Krall
 
🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...
🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...
🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...
SanjeetMishra29
 
UNIT 3 Software Engineering (BCS601) EIOV.pdf
UNIT 3 Software Engineering (BCS601) EIOV.pdfUNIT 3 Software Engineering (BCS601) EIOV.pdf
UNIT 3 Software Engineering (BCS601) EIOV.pdf
sikarwaramit089
 
Dahua Smart Cityyyyyyyyyyyyyyyyyy2025.pdf
Dahua Smart Cityyyyyyyyyyyyyyyyyy2025.pdfDahua Smart Cityyyyyyyyyyyyyyyyyy2025.pdf
Dahua Smart Cityyyyyyyyyyyyyyyyyy2025.pdf
PawachMetharattanara
 
Personal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.pptPersonal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.ppt
ganjangbegu579
 
hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .
NABLAS株式会社
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdfLittle Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
gori42199
 
Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025
Antonin Danalet
 
Lecture - 7 Canals of the topic of the civil engineering
Lecture - 7  Canals of the topic of the civil engineeringLecture - 7  Canals of the topic of the civil engineering
Lecture - 7 Canals of the topic of the civil engineering
MJawadkhan1
 

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
  翻译: