SlideShare a Scribd company logo
Huffman Coding
Prepared By:
Mr. Zeeshan Mubeen (Senior Lecturer, RSCI)
Unit No. 3
Huffman Coding
• Huffman Coding is a famous Greedy Algorithm.
• It is used for the lossless compression of data.
• It uses variable length encoding.
• It assigns variable length code to all the characters.
• The code length of a character depends on how frequently it occurs
in the given text.
• The character which occurs most frequently gets the smallest code.
• The character which occurs least frequently gets the largest code.
• It is also known as Huffman Encoding.
Major Steps in Huffman Coding-
• There are two major steps in Huffman Coding-
1. Building a Huffman Tree from the input characters.
2. Assigning code to the characters by traversing the Huffman
Tree.
Huffman.Encodingpptx Variable length coding
Huffman.Encodingpptx Variable length coding
Huffman Tree
Step-01:
• Create a leaf node for each character of the text.
• Leaf node of a character contains the occurring frequency of that
character.
Step-02:
• Arrange all the nodes in increasing order of their frequency value.
Step-03:
• Considering the first two nodes having minimum frequency,
• Create a new internal node.
• The frequency of this new node is the sum of frequency of those
two nodes.
• Make the first node as a left child and the other node as a right child
of the newly created node.
PRACTICEPROBLEMBASEDONHUFFMANCODING-
Characters Frequencies
a 10
e 15
i 12
o 3
u 4
s 13
T 1
A file contains the following characters with the frequencies as shown. If Huffman
Coding is used for data compression, determine
Solution:
Step-01:
Step-02:
Step-03:
Step-04:
Step-05:
Step-06
Step-07:
Following this rule, the
Huffman Code for each
character is-
•a = 111
•e = 10
•i = 00
•o = 11001
•u = 1101
•s = 01
•t = 11000
Fix length Vs Huffman code
Charac
ters
Freque
ncies
Fix
length
code
Cost
a 10 000 30
e 15 001 45
i 12 010 36
o 3 011 9
u 4 100 12
s 13 101 39
t 1 110 3
=174
Charact
ers
Freq
uenci
es
Huffman
code Cost
a 10 111 30
e 15 10 30
i 12 00 24
o 3 11001 15
u 4 1101 16
s 13 01 26
t 1 11000 5
=146

More Related Content

PPTX
5c. huffman coding using greedy technique.pptx
Suma Raj
 
PPTX
Huffman Codes
Md. Shafiuzzaman Hira
 
PDF
Implementation of Lossless Compression Algorithms for Text Data
BRNSSPublicationHubI
 
PDF
DSA Presentetion Huffman tree.pdf
GaneshPawar819187
 
PPT
Greedy Algorithms Huffman Coding.ppt
Ruchika Sinha
 
PPTX
Huffman coding || Huffman Tree
Gurunadh Guru
 
PPTX
Huffman coding || Huffman Tree
SatishKumarInumarthi
 
PDF
Huffman
keerthi vasan
 
5c. huffman coding using greedy technique.pptx
Suma Raj
 
Huffman Codes
Md. Shafiuzzaman Hira
 
Implementation of Lossless Compression Algorithms for Text Data
BRNSSPublicationHubI
 
DSA Presentetion Huffman tree.pdf
GaneshPawar819187
 
Greedy Algorithms Huffman Coding.ppt
Ruchika Sinha
 
Huffman coding || Huffman Tree
Gurunadh Guru
 
Huffman coding || Huffman Tree
SatishKumarInumarthi
 
Huffman
keerthi vasan
 

Similar to Huffman.Encodingpptx Variable length coding (20)

PDF
Huffman
keerthi vasan
 
DOCX
Huffman Coding is a technique of compressing data
Kumari99
 
PPTX
Data structures' project
Behappy Seehappy
 
PDF
Huffman Text Compression Technique
Universitas Pembangunan Panca Budi
 
PDF
Huffman Encoding Algorithm - Concepts and Example
MaryJacob24
 
PPTX
Huffman Coding
Muhammad Saqib Rehan
 
PPTX
Counting trees.pptx
mdshafiullah18
 
PDF
j001adcpresentation-2112170415 23.pdf
HarshSharma71048
 
PPTX
Huffman Algorithm and its Application by Ekansh Agarwal
Ekansh Agarwal
 
PPTX
Farhana shaikh webinar_huffman coding
Farhana Shaikh
 
PPTX
Huffman Algorithm By Shuhin
suhin4000
 
PPTX
Huffman codes
Nargis Ehsan
 
DOC
Huffman coding01
Nv Thejaswini
 
DOC
HuffmanCoding01.doc
Qwertty3
 
PPT
16_Greedy_Algorithms presentation paradigm
GMKosgiker
 
PPTX
t.pptx hd gsd unduf jdsnfijnfi bndsfuu ubfuh
chouhangulbadansing
 
PPT
16_Greedy_Algorithms Greedy_AlgorithmsGreedy_Algorithms
Shanmuganathan C
 
PPT
16_Greedy_Algorithms.ppt
talwandibhindran
 
PPT
16_Greedy_Algorithms.ppt
DrAliKMattar
 
PPTX
Huffman Algorithm for File Compression.pptx
kazmijaffar890
 
Huffman
keerthi vasan
 
Huffman Coding is a technique of compressing data
Kumari99
 
Data structures' project
Behappy Seehappy
 
Huffman Text Compression Technique
Universitas Pembangunan Panca Budi
 
Huffman Encoding Algorithm - Concepts and Example
MaryJacob24
 
Huffman Coding
Muhammad Saqib Rehan
 
Counting trees.pptx
mdshafiullah18
 
j001adcpresentation-2112170415 23.pdf
HarshSharma71048
 
Huffman Algorithm and its Application by Ekansh Agarwal
Ekansh Agarwal
 
Farhana shaikh webinar_huffman coding
Farhana Shaikh
 
Huffman Algorithm By Shuhin
suhin4000
 
Huffman codes
Nargis Ehsan
 
Huffman coding01
Nv Thejaswini
 
HuffmanCoding01.doc
Qwertty3
 
16_Greedy_Algorithms presentation paradigm
GMKosgiker
 
t.pptx hd gsd unduf jdsnfijnfi bndsfuu ubfuh
chouhangulbadansing
 
16_Greedy_Algorithms Greedy_AlgorithmsGreedy_Algorithms
Shanmuganathan C
 
16_Greedy_Algorithms.ppt
talwandibhindran
 
16_Greedy_Algorithms.ppt
DrAliKMattar
 
Huffman Algorithm for File Compression.pptx
kazmijaffar890
 
Ad

Recently uploaded (20)

DOCX
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
PPTX
Inventory management chapter in automation and robotics.
atisht0104
 
PPTX
ternal cell structure: leadership, steering
hodeeesite4
 
PPTX
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
PPTX
22PCOAM21 Data Quality Session 3 Data Quality.pptx
Guru Nanak Technical Institutions
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
PPTX
easa module 3 funtamental electronics.pptx
tryanothert7
 
PDF
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
PPTX
EE3303-EM-I 25.7.25 electrical machines.pptx
Nagen87
 
PPTX
22PCOAM21 Session 1 Data Management.pptx
Guru Nanak Technical Institutions
 
PPTX
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
PPTX
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
PPTX
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
PPT
Lecture in network security and mobile computing
AbdullahOmar704132
 
PDF
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
PDF
Queuing formulas to evaluate throughputs and servers
gptshubham
 
PDF
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
PDF
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
Inventory management chapter in automation and robotics.
atisht0104
 
ternal cell structure: leadership, steering
hodeeesite4
 
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
22PCOAM21 Data Quality Session 3 Data Quality.pptx
Guru Nanak Technical Institutions
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
easa module 3 funtamental electronics.pptx
tryanothert7
 
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
EE3303-EM-I 25.7.25 electrical machines.pptx
Nagen87
 
22PCOAM21 Session 1 Data Management.pptx
Guru Nanak Technical Institutions
 
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
Lecture in network security and mobile computing
AbdullahOmar704132
 
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
Queuing formulas to evaluate throughputs and servers
gptshubham
 
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
Ad

Huffman.Encodingpptx Variable length coding

  • 1. Huffman Coding Prepared By: Mr. Zeeshan Mubeen (Senior Lecturer, RSCI) Unit No. 3
  • 2. Huffman Coding • Huffman Coding is a famous Greedy Algorithm. • It is used for the lossless compression of data. • It uses variable length encoding. • It assigns variable length code to all the characters. • The code length of a character depends on how frequently it occurs in the given text. • The character which occurs most frequently gets the smallest code. • The character which occurs least frequently gets the largest code. • It is also known as Huffman Encoding.
  • 3. Major Steps in Huffman Coding- • There are two major steps in Huffman Coding- 1. Building a Huffman Tree from the input characters. 2. Assigning code to the characters by traversing the Huffman Tree.
  • 6. Huffman Tree Step-01: • Create a leaf node for each character of the text. • Leaf node of a character contains the occurring frequency of that character. Step-02: • Arrange all the nodes in increasing order of their frequency value. Step-03: • Considering the first two nodes having minimum frequency, • Create a new internal node. • The frequency of this new node is the sum of frequency of those two nodes. • Make the first node as a left child and the other node as a right child of the newly created node.
  • 7. PRACTICEPROBLEMBASEDONHUFFMANCODING- Characters Frequencies a 10 e 15 i 12 o 3 u 4 s 13 T 1 A file contains the following characters with the frequencies as shown. If Huffman Coding is used for data compression, determine
  • 14. Following this rule, the Huffman Code for each character is- •a = 111 •e = 10 •i = 00 •o = 11001 •u = 1101 •s = 01 •t = 11000
  • 15. Fix length Vs Huffman code Charac ters Freque ncies Fix length code Cost a 10 000 30 e 15 001 45 i 12 010 36 o 3 011 9 u 4 100 12 s 13 101 39 t 1 110 3 =174 Charact ers Freq uenci es Huffman code Cost a 10 111 30 e 15 10 30 i 12 00 24 o 3 11001 15 u 4 1101 16 s 13 01 26 t 1 11000 5 =146