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

PPT
Huffman coding presentation Sukkur iba.ppt
PPTX
Huffman's Alforithm
PDF
DSA Presentetion Huffman tree.pdf
PPTX
5c. huffman coding using greedy technique.pptx
PDF
Module-IV 094.pdf
PDF
j001adcpresentation-2112170415 23.pdf
PPTX
Huffman Algorithm and its Application by Ekansh Agarwal
PPTX
Text compression
Huffman coding presentation Sukkur iba.ppt
Huffman's Alforithm
DSA Presentetion Huffman tree.pdf
5c. huffman coding using greedy technique.pptx
Module-IV 094.pdf
j001adcpresentation-2112170415 23.pdf
Huffman Algorithm and its Application by Ekansh Agarwal
Text compression

Similar to Huffman.Encodingpptx Variable length coding (20)

PPTX
Huffman ppt
PDF
Data communication & computer networking: Huffman algorithm
PPT
Komdat-Kompresi Data
PPTX
Huffman's algorithm in Data Structure
PPT
add9.5.ppt
PPTX
Huffman Coding
PDF
Huffman and Arithmetic coding - Performance analysis
PPTX
Farhana shaikh webinar_huffman coding
PDF
Lossless image compression.(1)
PDF
12_HuffmanhsjsjsjjsiejjssjjejsjCoding_pdf.pdf
PPTX
Huffman Codes
PPT
computer notes - Data Structures - 24
PPT
PPT
Lossless
PDF
Data Communication & Computer network: Shanon fano coding
PPTX
Huffman coding
PPT
Chapter%202%20 %20 Text%20compression(2)
 
PPTX
Data structures' project
PPT
Huffman > Data Structures & Algorithums
PPT
Hufman coding basic
Huffman ppt
Data communication & computer networking: Huffman algorithm
Komdat-Kompresi Data
Huffman's algorithm in Data Structure
add9.5.ppt
Huffman Coding
Huffman and Arithmetic coding - Performance analysis
Farhana shaikh webinar_huffman coding
Lossless image compression.(1)
12_HuffmanhsjsjsjjsiejjssjjejsjCoding_pdf.pdf
Huffman Codes
computer notes - Data Structures - 24
Lossless
Data Communication & Computer network: Shanon fano coding
Huffman coding
Chapter%202%20 %20 Text%20compression(2)
 
Data structures' project
Huffman > Data Structures & Algorithums
Hufman coding basic
Ad

Recently uploaded (20)

PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
CH1 Production IntroductoryConcepts.pptx
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PDF
PPT on Performance Review to get promotions
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
additive manufacturing of ss316l using mig welding
PPTX
web development for engineering and engineering
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPT
Project quality management in manufacturing
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Sustainable Sites - Green Building Construction
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPT
Mechanical Engineering MATERIALS Selection
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
Automation-in-Manufacturing-Chapter-Introduction.pdf
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
CH1 Production IntroductoryConcepts.pptx
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPT on Performance Review to get promotions
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
UNIT-1 - COAL BASED THERMAL POWER PLANTS
additive manufacturing of ss316l using mig welding
web development for engineering and engineering
Operating System & Kernel Study Guide-1 - converted.pdf
bas. eng. economics group 4 presentation 1.pptx
Project quality management in manufacturing
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Sustainable Sites - Green Building Construction
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Mechanical Engineering MATERIALS Selection
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Model Code of Practice - Construction Work - 21102022 .pdf
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