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)

PPT
Logical Agents
Yasir Khan
 
DOC
Chapter 4 (final)
Nateshwar Kamlesh
 
PPTX
Artificial Intelligence Notes Unit 3
DigiGurukul
 
PDF
State of AI Report 2023 - Air Street Capital
AI Geek (wishesh)
 
PPTX
ID3 ALGORITHM
HARDIK SINGH
 
PPTX
Leaky Bucket & Tocken Bucket - Traffic shaping
Vimal Dewangan
 
PPTX
Local search algorithm
Megha Sharma
 
PPTX
Introduction to Machine Learning
Lior Rokach
 
PPTX
Inference in First-Order Logic
Junya Tanaka
 
PPTX
Knowledge representation and Predicate logic
Amey Kerkar
 
PPSX
Perceptron (neural network)
EdutechLearners
 
PPTX
Ai quantifiers
Tayyaba Jabeen
 
PDF
Rough K Means - Numerical Example
Dr.E.N.Sathishkumar
 
PPTX
Artificial intelligence- Logic Agents
Nuruzzaman Milon
 
PPTX
Control Strategies in AI
Amey Kerkar
 
PPT
Unit I & II in Principles of Soft computing
Sivagowry Shathesh
 
PPT
Principles of soft computing-Associative memory networks
Sivagowry Shathesh
 
PDF
Syntactic analysis in NLP
kartikaVashisht
 
PDF
Dimensionality Reduction
mrizwan969
 
PPT
AI Lecture 6 (logical agents)
Tajim Md. Niamat Ullah Akhund
 
Logical Agents
Yasir Khan
 
Chapter 4 (final)
Nateshwar Kamlesh
 
Artificial Intelligence Notes Unit 3
DigiGurukul
 
State of AI Report 2023 - Air Street Capital
AI Geek (wishesh)
 
ID3 ALGORITHM
HARDIK SINGH
 
Leaky Bucket & Tocken Bucket - Traffic shaping
Vimal Dewangan
 
Local search algorithm
Megha Sharma
 
Introduction to Machine Learning
Lior Rokach
 
Inference in First-Order Logic
Junya Tanaka
 
Knowledge representation and Predicate logic
Amey Kerkar
 
Perceptron (neural network)
EdutechLearners
 
Ai quantifiers
Tayyaba Jabeen
 
Rough K Means - Numerical Example
Dr.E.N.Sathishkumar
 
Artificial intelligence- Logic Agents
Nuruzzaman Milon
 
Control Strategies in AI
Amey Kerkar
 
Unit I & II in Principles of Soft computing
Sivagowry Shathesh
 
Principles of soft computing-Associative memory networks
Sivagowry Shathesh
 
Syntactic analysis in NLP
kartikaVashisht
 
Dimensionality Reduction
mrizwan969
 
AI Lecture 6 (logical agents)
Tajim Md. Niamat Ullah Akhund
 

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

PPT
Huffman Coding.ppt
MuktarHossain13
 
PPTX
Huffman Coding
Muhammad Saqib Rehan
 
PPT
Huffmans code
Vinay379568
 
PPT
huffman ppt
PatrickIasiahLBelga
 
PPTX
Huffman.pptx
HarisMasood20
 
PPT
Huffman code presentation and their operation
HODCSE170941
 
PPTX
5c. huffman coding using greedy technique.pptx
Suma Raj
 
PPTX
Data Compression in Multimedia
lalithambiga kamaraj
 
PPTX
Data CompressionMultimedia
lalithambiga kamaraj
 
PPT
Greedy Algorithms Huffman Coding.ppt
Ruchika Sinha
 
PPT
Hufman coding basic
radthees
 
DOC
Huffman coding01
Nv Thejaswini
 
DOC
HuffmanCoding01.doc
Qwertty3
 
PPT
Data Structure and Algorithms Huffman Coding Algorithm
ManishPrajapati78
 
DOCX
Huffman Coding is a technique of compressing data
Kumari99
 
PDF
Unit 2 Lecture notes on Huffman coding
Dr Piyush Charan
 
PPTX
Huffman Codes
Md. Shafiuzzaman Hira
 
PPTX
Farhana shaikh webinar_huffman coding
Farhana Shaikh
 
PPTX
Data structures' project
Behappy Seehappy
 
PPTX
Huffman coding
Nazmul Hyder
 
Huffman Coding.ppt
MuktarHossain13
 
Huffman Coding
Muhammad Saqib Rehan
 
Huffmans code
Vinay379568
 
huffman ppt
PatrickIasiahLBelga
 
Huffman.pptx
HarisMasood20
 
Huffman code presentation and their operation
HODCSE170941
 
5c. huffman coding using greedy technique.pptx
Suma Raj
 
Data Compression in Multimedia
lalithambiga kamaraj
 
Data CompressionMultimedia
lalithambiga kamaraj
 
Greedy Algorithms Huffman Coding.ppt
Ruchika Sinha
 
Hufman coding basic
radthees
 
Huffman coding01
Nv Thejaswini
 
HuffmanCoding01.doc
Qwertty3
 
Data Structure and Algorithms Huffman Coding Algorithm
ManishPrajapati78
 
Huffman Coding is a technique of compressing data
Kumari99
 
Unit 2 Lecture notes on Huffman coding
Dr Piyush Charan
 
Huffman Codes
Md. Shafiuzzaman Hira
 
Farhana shaikh webinar_huffman coding
Farhana Shaikh
 
Data structures' project
Behappy Seehappy
 
Huffman coding
Nazmul Hyder
 
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
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
community health nursing question paper 2.pdf
Prince kumar
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 

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