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

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.ppt
DrAliKMattar
 
PPT
16_Greedy_Algorithms Greedy_AlgorithmsGreedy_Algorithms
Shanmuganathan C
 
PPT
16_Greedy_Algorithms.ppt
talwandibhindran
 
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.ppt
DrAliKMattar
 
16_Greedy_Algorithms Greedy_AlgorithmsGreedy_Algorithms
Shanmuganathan C
 
16_Greedy_Algorithms.ppt
talwandibhindran
 
Huffman Algorithm for File Compression.pptx
kazmijaffar890
 

Recently uploaded (20)

PPTX
Depth First Search Algorithm in 🧠 DFS in Artificial Intelligence (AI)
rafeeqshaik212002
 
PPTX
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
PPTX
Types of Bearing_Specifications_PPT.pptx
PranjulAgrahariAkash
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PPTX
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
PPTX
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
PPTX
Day2 B2 Best.pptx
helenjenefa1
 
DOCX
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
PDF
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
PPTX
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
PPTX
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
PDF
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
PPTX
GitOps_Without_K8s_Training simple one without k8s
DanialHabibi2
 
PPTX
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
PPTX
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PDF
Set Relation Function Practice session 24.05.2025.pdf
DrStephenStrange4
 
PDF
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
PDF
Design Thinking basics for Engineers.pdf
CMR University
 
PPTX
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
Depth First Search Algorithm in 🧠 DFS in Artificial Intelligence (AI)
rafeeqshaik212002
 
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
Types of Bearing_Specifications_PPT.pptx
PranjulAgrahariAkash
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
Day2 B2 Best.pptx
helenjenefa1
 
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
GitOps_Without_K8s_Training simple one without k8s
DanialHabibi2
 
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
Set Relation Function Practice session 24.05.2025.pdf
DrStephenStrange4
 
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
Design Thinking basics for Engineers.pdf
CMR University
 
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
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