SlideShare a Scribd company logo
1 of 17
Download to read offline
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

Similar to j001adcpresentation-2112170415 23.pdf

Hufman coding basic
Hufman coding basicHufman coding basic
Hufman coding basicradthees
 
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 DataBRNSSPublicationHubI
 
Paper id 24201469
Paper id 24201469Paper id 24201469
Paper id 24201469IJRAT
 
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 algorithmDr Sandeep Kumar Poonia
 
DSA Presentetion Huffman tree.pdf
DSA Presentetion Huffman tree.pdfDSA Presentetion Huffman tree.pdf
DSA Presentetion Huffman tree.pdfGaneshPawar819187
 
2.3 unit-ii-text-compression-a-outline-compression-techniques-run-length-codi...
2.3 unit-ii-text-compression-a-outline-compression-techniques-run-length-codi...2.3 unit-ii-text-compression-a-outline-compression-techniques-run-length-codi...
2.3 unit-ii-text-compression-a-outline-compression-techniques-run-length-codi...Helan4
 
Single-Bit Parity Detection and Correction using Hamming Code 7-Bit Model
Single-Bit Parity Detection and Correction using Hamming Code 7-Bit ModelSingle-Bit Parity Detection and Correction using Hamming Code 7-Bit Model
Single-Bit Parity Detection and Correction using Hamming Code 7-Bit ModelUniversitas Pembangunan Panca Budi
 
IP Header & IP Fragmentation (Network Layer Protocols).pptx
IP Header & IP Fragmentation (Network Layer Protocols).pptxIP Header & IP Fragmentation (Network Layer Protocols).pptx
IP Header & IP Fragmentation (Network Layer Protocols).pptxIda Seraphim
 
Huffman and Arithmetic coding - Performance analysis
Huffman and Arithmetic coding - Performance analysisHuffman and Arithmetic coding - Performance analysis
Huffman and Arithmetic coding - Performance analysisRamakant Soni
 
LEC 7-DS ALGO(expression and huffman).pdf
LEC 7-DS  ALGO(expression and huffman).pdfLEC 7-DS  ALGO(expression and huffman).pdf
LEC 7-DS ALGO(expression and huffman).pdfMuhammadUmerIhtisham
 

Similar to j001adcpresentation-2112170415 23.pdf (20)

Hufman coding basic
Hufman coding basicHufman coding basic
Hufman coding basic
 
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
 
Text compression
Text compressionText compression
Text compression
 
Paper id 24201469
Paper id 24201469Paper id 24201469
Paper id 24201469
 
Huffman coding || Huffman Tree
Huffman coding || Huffman TreeHuffman coding || Huffman Tree
Huffman coding || Huffman Tree
 
Data structures' project
Data structures' projectData structures' project
Data structures' project
 
Huffman Coding
Huffman CodingHuffman Coding
Huffman Coding
 
Komdat-Kompresi Data
Komdat-Kompresi DataKomdat-Kompresi Data
Komdat-Kompresi Data
 
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
 
Adaptive huffman coding
Adaptive huffman codingAdaptive huffman coding
Adaptive huffman coding
 
Huffman Text Compression Technique
Huffman Text Compression TechniqueHuffman Text Compression Technique
Huffman Text Compression Technique
 
DSA Presentetion Huffman tree.pdf
DSA Presentetion Huffman tree.pdfDSA Presentetion Huffman tree.pdf
DSA Presentetion Huffman tree.pdf
 
2.3 unit-ii-text-compression-a-outline-compression-techniques-run-length-codi...
2.3 unit-ii-text-compression-a-outline-compression-techniques-run-length-codi...2.3 unit-ii-text-compression-a-outline-compression-techniques-run-length-codi...
2.3 unit-ii-text-compression-a-outline-compression-techniques-run-length-codi...
 
Huffman
HuffmanHuffman
Huffman
 
Huffman
HuffmanHuffman
Huffman
 
Single-Bit Parity Detection and Correction using Hamming Code 7-Bit Model
Single-Bit Parity Detection and Correction using Hamming Code 7-Bit ModelSingle-Bit Parity Detection and Correction using Hamming Code 7-Bit Model
Single-Bit Parity Detection and Correction using Hamming Code 7-Bit Model
 
IP Header & IP Fragmentation (Network Layer Protocols).pptx
IP Header & IP Fragmentation (Network Layer Protocols).pptxIP Header & IP Fragmentation (Network Layer Protocols).pptx
IP Header & IP Fragmentation (Network Layer Protocols).pptx
 
Huffman and Arithmetic coding - Performance analysis
Huffman and Arithmetic coding - Performance analysisHuffman and Arithmetic coding - Performance analysis
Huffman and Arithmetic coding - Performance analysis
 
LEC 7-DS ALGO(expression and huffman).pdf
LEC 7-DS  ALGO(expression and huffman).pdfLEC 7-DS  ALGO(expression and huffman).pdf
LEC 7-DS ALGO(expression and huffman).pdf
 
Huffman codes
Huffman codesHuffman codes
Huffman codes
 

Recently uploaded

Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 

Recently uploaded (20)

Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 

j001adcpresentation-2112170415 23.pdf

  • 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