SlideShare a Scribd company logo
Introduction to Data communication
Topic : Huffman Algorithm
Lecture #12
Dr Rajiv Srivastava
Director
Sagar Institute of Research & Technology (SIRT)
Sagar Group of Institutions, Bhopal
http://www.sirtbhopal.ac.in
Unit 1
Lecture 12
• In computer science and information theory, a
Huffman code is a particular type of optimal
prefix code that is commonly used for lossless
data compression.
• Huffman coding is a form of statistical coding
• Not all characters occur with the same
frequency!
• Yet all characters are allocated the same
amount of space
Huffman Encoding
• Huffman coding, however, makes coding more
efficient. In this mechanism we assign shorter
codes to characters that occur more frequently
and longer codes that occur less frequently.
• For example, E and T, the two characters that
occur most frequently in the English language,
are assigned one bit each.
• C,G,K,R,S,U and W are the next most frequently
and are assigned three bits each , and so on.
• In a given piece of text, only some of the
characters will require the maximum bit
length.
• The overall length of the transmission,
therefore, is shorter than that resulting from
fixed-length encoding.
• Difficulty arises, however, if the bit patterns
associated with each character are assigned
randomly.
• Consider the example given figure.
• Bit assignments based on frequency of the
character.
E : 0 T : 1
A: 00 I : 01 M : 10
C : 000 D : 001 G : 010 O : 100 R : 101 S : 110 U : 111
• Multiple interpretations of transmitted data
code sent
First interpretation
Second interpretation
Third interpretation
00101010011110
0 01 010 100 1 111 0
E I G O T U E
00 10 101 0 01 110
A M R E I S
001 010 100 111 10
D G O U M
• Huffman coding is designed to counter this
ambiguity while retaining the bit count
advantages of a compression code.
• Not only does it vary the length of the code
based on the frequency of the character
represented, but each character code is
chosen in such a way that prefix of another
code.
• For example, no three-bit code has the same
pattern as the first three bits of a four or five-
bit code.
Character Tree
• Using the character set from the example above,
let’s examine how a Huffman code is built.
1. First we organize the entire character set into a
row, ordered according to frequency from
highest to lowest (or vice Versa). Each character
is now a node at the leaf level of a tree.
E = 15 T = 12 A = 10 I = 08 M = 07 N = 06 C = 05
D = 05 G = 04 K = 04 O = 03 R = 03 S = 02 U = 02
2. Next, we find the two nodes with the smallest
combined frequency weighting and join them
to form a third node, resulting in a simple
two-level tree, the weight of the new node is
the combined weight of the original two
nodes.
This node, one level up from the leaves, is
eligible to be combined with other nodes.
Remember the same weight of the two
nodes chosen must be smaller than the
combination of any other possible choices.
3. We repeat step 2 until all of the nodes, on
every level, are combined into a single tree.
Data communication & computer networking:  Huffman algorithm
Data communication & computer networking:  Huffman algorithm
Assigning the codes
• Once the tree is complete, we use it to assign
codes to each character. First we assign a bit
value to each branch (see figure F.7). Starting
from the root (top node).
• We assign 0 to the branch and 1 to the right
branch and repeat this pattern at each node.
• Which branch becomes 0 and which becomes
1 is left to the designer as long as the
assignments are consistent throughout the
tree.
• Code assignment
• Code assignment table.
Character Frequency Code Character Frequency code
E 15 100 D 5 0101
T 12 111 G 4 0110
A 10 000 K 4 0111
I 8 001 O 3 11000
M 7 1010 R 3 11001
N 6 1011 S 2 11010
c 5 0100 U 2 11011
DECODING
• A message encoded in this fashion can be
interpreted without ambiguity, using the
following process :
1. The receiver stores the first three bits
received in memory and attempts to match
them with one of the three bit codes. If a
match is found, that character is selected and
the three bits are discarded. The receiver
then repeats this step with the next three
bits.
2. If a match is not found, the receiver reads the
neat bit from the stream and adds it to the
first three. It then attempts to find a match
among the four-bit codes. If a match is found,
the corresponding character is selected and
the bits are discarded.
3. If a match is not found, the receiver reads the
neat bit from the stream and tries to match all
the five bits to one of the five bit codes. If a
match is found, the character is selected and
the bits are discarded.
• Unambiguous transmission
sent
Interpreted
1101010111110010100
11010 1011 111 001 0100
S N T I C
Thank You
Dr Rajiv Srivastava
Director
Sagar Institute of Research & Technology (SIRT)
Sagar Group of Institutions, Bhopal
http://www.sirtbhopal.ac.in

More Related Content

What's hot (20)

PPTX
Bundled Attributes by R.Chinthamani.pptx
SindhuVelmukull
 
PPTX
Attributes of Output Primitives
Renita Santhmayora
 
PPTX
Computer graphics basic transformation
Selvakumar Gna
 
PPTX
Single pass assembler
Bansari Shah
 
PPTX
Polygon filling algorithm
Aparna Joshi
 
PPTX
Attributes of output Primitive
SachiniGunawardana
 
PPTX
Graphics Primitives and CG Display Devices
DIPIKA83
 
PPT
program partitioning and scheduling IN Advanced Computer Architecture
Pankaj Kumar Jain
 
PPTX
Error detection recovery
Tech_MX
 
PPTX
CATHODE RAY TUBE IN COMPUTER GRAPHICS
nehrurevathy
 
PPT
Fill area algorithms
Kumar
 
PPT
Services provided by os
Sumant Diwakar
 
PPT
Loop invariant computation
ReachLocal Services India
 
PPTX
Raster scan system & random scan system
shalinikarunakaran1
 
PPT
Simulation & Modeling - Smilulation Queuing System
Maruf Rion
 
PPT
Logical Clocks (Distributed computing)
Sri Prasanna
 
PPTX
Lecture 02 lexical analysis
Iffat Anjum
 
PPTX
Integration testing
queen jemila
 
PPTX
Window to Viewport Transformation in Computer Graphics with.pptx
Dolchandra
 
PPT
Design issues for the layers
jayaprakash
 
Bundled Attributes by R.Chinthamani.pptx
SindhuVelmukull
 
Attributes of Output Primitives
Renita Santhmayora
 
Computer graphics basic transformation
Selvakumar Gna
 
Single pass assembler
Bansari Shah
 
Polygon filling algorithm
Aparna Joshi
 
Attributes of output Primitive
SachiniGunawardana
 
Graphics Primitives and CG Display Devices
DIPIKA83
 
program partitioning and scheduling IN Advanced Computer Architecture
Pankaj Kumar Jain
 
Error detection recovery
Tech_MX
 
CATHODE RAY TUBE IN COMPUTER GRAPHICS
nehrurevathy
 
Fill area algorithms
Kumar
 
Services provided by os
Sumant Diwakar
 
Loop invariant computation
ReachLocal Services India
 
Raster scan system & random scan system
shalinikarunakaran1
 
Simulation & Modeling - Smilulation Queuing System
Maruf Rion
 
Logical Clocks (Distributed computing)
Sri Prasanna
 
Lecture 02 lexical analysis
Iffat Anjum
 
Integration testing
queen jemila
 
Window to Viewport Transformation in Computer Graphics with.pptx
Dolchandra
 
Design issues for the layers
jayaprakash
 

Similar to Data communication & computer networking: Huffman algorithm (20)

PPTX
Data Compression - Text Compression - Run Length Encoding
MANISH T I
 
PDF
Huffman Text Compression Technique
Universitas Pembangunan Panca Budi
 
PDF
Implementation of Lossless Compression Algorithms for Text Data
BRNSSPublicationHubI
 
PPTX
Huffman.Encodingpptx Variable length coding
zeeshanmubeen1
 
PDF
Huffman Encoding Pr
anithabalaprabhu
 
PDF
Module-IV 094.pdf
SamrajECE
 
PPT
Lossless
anithabalaprabhu
 
PPT
Lossless
Vishal Suri
 
PDF
Classical encryption techniques
Dr.Florence Dayana
 
PPTX
Text compression
Sammer Qader
 
PPT
Data Structures 5
Dr.Umadevi V
 
PPTX
Data structures' project
Behappy Seehappy
 
PPTX
Suffix Tree and Suffix Array
Harshit Agarwal
 
PDF
K mer index of dna sequence based on hash
ijcsa
 
PPTX
Huffman analysis
Abubakar Sultan
 
PPTX
Central dogma and transcription slides
Quanina Quan
 
PPTX
240311_JW_labseminar[Sequence to Sequence Learning with Neural Networks].pptx
thanhdowork
 
PPT
Komdat-Kompresi Data
mursalinfajri007
 
PPT
Multiplexing concepts and techniques.ppt
azizurrahman483685
 
PDF
Dna data compression algorithms based on redundancy
ijfcstjournal
 
Data Compression - Text Compression - Run Length Encoding
MANISH T I
 
Huffman Text Compression Technique
Universitas Pembangunan Panca Budi
 
Implementation of Lossless Compression Algorithms for Text Data
BRNSSPublicationHubI
 
Huffman.Encodingpptx Variable length coding
zeeshanmubeen1
 
Huffman Encoding Pr
anithabalaprabhu
 
Module-IV 094.pdf
SamrajECE
 
Lossless
Vishal Suri
 
Classical encryption techniques
Dr.Florence Dayana
 
Text compression
Sammer Qader
 
Data Structures 5
Dr.Umadevi V
 
Data structures' project
Behappy Seehappy
 
Suffix Tree and Suffix Array
Harshit Agarwal
 
K mer index of dna sequence based on hash
ijcsa
 
Huffman analysis
Abubakar Sultan
 
Central dogma and transcription slides
Quanina Quan
 
240311_JW_labseminar[Sequence to Sequence Learning with Neural Networks].pptx
thanhdowork
 
Komdat-Kompresi Data
mursalinfajri007
 
Multiplexing concepts and techniques.ppt
azizurrahman483685
 
Dna data compression algorithms based on redundancy
ijfcstjournal
 
Ad

More from Dr Rajiv Srivastava (20)

PPTX
Trends of it
Dr Rajiv Srivastava
 
PDF
Placement at sagar group Bhopal | SIRT College Bhopal
Dr Rajiv Srivastava
 
PPTX
How to Prepare for Group Discussion
Dr Rajiv Srivastava
 
PPTX
Unix ppt
Dr Rajiv Srivastava
 
PPTX
SAGE GROUP - BEST ENGINEERING COLLEGE IN BHOPAL MP
Dr Rajiv Srivastava
 
PPT
lecture on data compression
Dr Rajiv Srivastava
 
PPT
Topic : X.25, Frame relay and ATM
Dr Rajiv Srivastava
 
PPT
Topic : B ISDN
Dr Rajiv Srivastava
 
PPT
Topic : ISDN(integrated services digital network) part 2
Dr Rajiv Srivastava
 
PPT
Topic: ISDN (Integrated Services Digital Network)
Dr Rajiv Srivastava
 
PPT
Topic: Virtual circuit & message switching
Dr Rajiv Srivastava
 
PPT
Topic Packet switching
Dr Rajiv Srivastava
 
PPT
Introduction to switching & circuit switching
Dr Rajiv Srivastava
 
PPT
Topic:Terminal handling & polling
Dr Rajiv Srivastava
 
PPT
Topic: Spread Spectrum
Dr Rajiv Srivastava
 
PPT
Applications of Time Division multiplexing : statistical TDM
Dr Rajiv Srivastava
 
PPT
Multiplexing : Wave Division Multiplexing
Dr Rajiv Srivastava
 
PPT
Multiplexing : FDM
Dr Rajiv Srivastava
 
PDF
Data Communication & Computer network: Shanon fano coding
Dr Rajiv Srivastava
 
PDF
Data Communication & Computer Networks : LZW compression method
Dr Rajiv Srivastava
 
Trends of it
Dr Rajiv Srivastava
 
Placement at sagar group Bhopal | SIRT College Bhopal
Dr Rajiv Srivastava
 
How to Prepare for Group Discussion
Dr Rajiv Srivastava
 
SAGE GROUP - BEST ENGINEERING COLLEGE IN BHOPAL MP
Dr Rajiv Srivastava
 
lecture on data compression
Dr Rajiv Srivastava
 
Topic : X.25, Frame relay and ATM
Dr Rajiv Srivastava
 
Topic : B ISDN
Dr Rajiv Srivastava
 
Topic : ISDN(integrated services digital network) part 2
Dr Rajiv Srivastava
 
Topic: ISDN (Integrated Services Digital Network)
Dr Rajiv Srivastava
 
Topic: Virtual circuit & message switching
Dr Rajiv Srivastava
 
Topic Packet switching
Dr Rajiv Srivastava
 
Introduction to switching & circuit switching
Dr Rajiv Srivastava
 
Topic:Terminal handling & polling
Dr Rajiv Srivastava
 
Topic: Spread Spectrum
Dr Rajiv Srivastava
 
Applications of Time Division multiplexing : statistical TDM
Dr Rajiv Srivastava
 
Multiplexing : Wave Division Multiplexing
Dr Rajiv Srivastava
 
Multiplexing : FDM
Dr Rajiv Srivastava
 
Data Communication & Computer network: Shanon fano coding
Dr Rajiv Srivastava
 
Data Communication & Computer Networks : LZW compression method
Dr Rajiv Srivastava
 
Ad

Recently uploaded (20)

PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPSX
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PPTX
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 

Data communication & computer networking: Huffman algorithm

  • 1. Introduction to Data communication Topic : Huffman Algorithm Lecture #12 Dr Rajiv Srivastava Director Sagar Institute of Research & Technology (SIRT) Sagar Group of Institutions, Bhopal http://www.sirtbhopal.ac.in
  • 3. • In computer science and information theory, a Huffman code is a particular type of optimal prefix code that is commonly used for lossless data compression. • Huffman coding is a form of statistical coding • Not all characters occur with the same frequency! • Yet all characters are allocated the same amount of space
  • 4. Huffman Encoding • Huffman coding, however, makes coding more efficient. In this mechanism we assign shorter codes to characters that occur more frequently and longer codes that occur less frequently. • For example, E and T, the two characters that occur most frequently in the English language, are assigned one bit each. • C,G,K,R,S,U and W are the next most frequently and are assigned three bits each , and so on.
  • 5. • In a given piece of text, only some of the characters will require the maximum bit length. • The overall length of the transmission, therefore, is shorter than that resulting from fixed-length encoding. • Difficulty arises, however, if the bit patterns associated with each character are assigned randomly. • Consider the example given figure.
  • 6. • Bit assignments based on frequency of the character. E : 0 T : 1 A: 00 I : 01 M : 10 C : 000 D : 001 G : 010 O : 100 R : 101 S : 110 U : 111
  • 7. • Multiple interpretations of transmitted data code sent First interpretation Second interpretation Third interpretation 00101010011110 0 01 010 100 1 111 0 E I G O T U E 00 10 101 0 01 110 A M R E I S 001 010 100 111 10 D G O U M
  • 8. • Huffman coding is designed to counter this ambiguity while retaining the bit count advantages of a compression code. • Not only does it vary the length of the code based on the frequency of the character represented, but each character code is chosen in such a way that prefix of another code. • For example, no three-bit code has the same pattern as the first three bits of a four or five- bit code.
  • 9. Character Tree • Using the character set from the example above, let’s examine how a Huffman code is built. 1. First we organize the entire character set into a row, ordered according to frequency from highest to lowest (or vice Versa). Each character is now a node at the leaf level of a tree. E = 15 T = 12 A = 10 I = 08 M = 07 N = 06 C = 05 D = 05 G = 04 K = 04 O = 03 R = 03 S = 02 U = 02
  • 10. 2. Next, we find the two nodes with the smallest combined frequency weighting and join them to form a third node, resulting in a simple two-level tree, the weight of the new node is the combined weight of the original two nodes. This node, one level up from the leaves, is eligible to be combined with other nodes. Remember the same weight of the two nodes chosen must be smaller than the combination of any other possible choices.
  • 11. 3. We repeat step 2 until all of the nodes, on every level, are combined into a single tree.
  • 14. Assigning the codes • Once the tree is complete, we use it to assign codes to each character. First we assign a bit value to each branch (see figure F.7). Starting from the root (top node). • We assign 0 to the branch and 1 to the right branch and repeat this pattern at each node. • Which branch becomes 0 and which becomes 1 is left to the designer as long as the assignments are consistent throughout the tree.
  • 16. • Code assignment table. Character Frequency Code Character Frequency code E 15 100 D 5 0101 T 12 111 G 4 0110 A 10 000 K 4 0111 I 8 001 O 3 11000 M 7 1010 R 3 11001 N 6 1011 S 2 11010 c 5 0100 U 2 11011
  • 17. DECODING • A message encoded in this fashion can be interpreted without ambiguity, using the following process : 1. The receiver stores the first three bits received in memory and attempts to match them with one of the three bit codes. If a match is found, that character is selected and the three bits are discarded. The receiver then repeats this step with the next three bits.
  • 18. 2. If a match is not found, the receiver reads the neat bit from the stream and adds it to the first three. It then attempts to find a match among the four-bit codes. If a match is found, the corresponding character is selected and the bits are discarded. 3. If a match is not found, the receiver reads the neat bit from the stream and tries to match all the five bits to one of the five bit codes. If a match is found, the character is selected and the bits are discarded.
  • 20. Thank You Dr Rajiv Srivastava Director Sagar Institute of Research & Technology (SIRT) Sagar Group of Institutions, Bhopal http://www.sirtbhopal.ac.in