SlideShare a Scribd company logo
C#ODE Studio
CS 102
Huffman Coding:
An Application of Binary
Trees and Priority Queues
C#ODE Studio
CS 102
Encoding and
Compression of Data
• Fax Machines
• ASCII
• Variations on ASCII
– min number of bits needed
– cost of savings
– patterns
– modifications
C#ODE Studio
CS 102
Purpose of Huffman
Coding
• Proposed by Dr. David A.
Huffman in 1952
– “A Method for the Construction
of Minimum Redundancy Codes”
• Applicable to many forms of
data transmission
– Our example: text files
C#ODE Studio
CS 102
The Basic Algorithm
• 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
– 1 char = 1 byte, be it e or x
C#ODE Studio
CS 102
The Basic Algorithm
• Any savings in tailoring codes
to frequency of character?
• Code word lengths are no longer
fixed like ASCII.
• Code word lengths vary and will
be shorter for the more
frequently used characters.
C#ODE Studio
CS 102
The (Real) Basic
Algorithm
1. Scan text to be compressed and tally
occurrence of all characters.
2. Sort or prioritize characters based on
number of occurrences in text.
3. Build Huffman code tree based on
prioritized list.
4. Perform a traversal of tree to determine
all code words.
5. Scan text again and create new file
using the Huffman codes.
C#ODE Studio
CS 102
Building a Tree
Scan the original text
• Consider the following short
text:
Eerie eyes seen near lake.
• Count up the occurrences of all
characters in the text
C#ODE Studio
CS 102
Building a Tree
Scan the original text
Eerie eyes seen near lake.
• What characters are present?
E e r i space
y s n a r l k .
C#ODE Studio
CS 102
Building a Tree
Scan the original text
Eerie eyes seen near lake.
• What is the frequency of each
character in the text?
Char Freq. Char Freq. Char Freq.
E 1 y 1 k 1
e 8 s 2 . 1
r 2 n 2
i 1 a 2
space 4 l 1
C#ODE Studio
CS 102
Building a Tree
Prioritize characters
• Create binary tree nodes with
character and frequency of
each character
• Place nodes in a priority
queue
– The lower the occurrence, the
higher the priority in the queue
C#ODE Studio
CS 102
Building a Tree
Prioritize characters
• Uses binary tree nodes
public class HuffNode
{
public char myChar;
public int myFrequency;
public HuffNode myLeft, myRight;
}
priorityQueue myQueue;
C#ODE Studio
CS 102
Building a Tree
• The queue after inserting all nodes
• Null Pointers are not shown
E
1
i
1
y
1
l
1
k
1
.
1
r
2
s
2
n
2
a
2
sp
4
e
8
C#ODE Studio
CS 102
Building a Tree
• While priority queue contains two
or more nodes
– Create new node
– Dequeue node and make it left subtree
– Dequeue next node and make it right
subtree
– Frequency of new node equals sum of
frequency of left and right children
– Enqueue new node back into queue
C#ODE Studio
CS 102
Building a Tree
E
1
i
1
y
1
l
1
k
1
.
1
r
2
s
2
n
2
a
2
sp
4
e
8
C#ODE Studio
CS 102
Building a Tree
E i
y
1
l
1
k
1
.
1
r
2
s
2
n
2
a
2
sp
4
e
8
2
C#ODE Studio
CS 102
Building a Tree
E i
y
1
l
1
k
1
.
1
r
2
s
2
n
2
a
2
sp
4
e
8
C#ODE Studio
CS 102
Building a Tree
E i
k
1
.
1
r
2
s
2
n
2
a
2
sp
4
e
8
y l
C#ODE Studio
CS 102
Building a Tree
E i
k
1
.
1
r
2
s
2
n
2
a
2
sp
4
e
8
2
y l
2
C#ODE Studio
CS 102
Building a Tree
E i
r
2
s
2
n
2
a
2
sp
4
e
8
2
y l
2
k .
2
C#ODE Studio
CS 102
Building a Tree
E i
r
2
s
2
n
2
a
2
sp
4
e
8
2
y l
2
k .
2
C#ODE Studio
CS 102
Building a Tree
E i
n
2
a
2
sp
4
e
8
2
y l
2
k .
2
r s
4
C#ODE Studio
CS 102
Building a Tree
E i
n
2
a
2
sp
4
e
8
2
y l
2
k .
2
r s
4
C#ODE Studio
CS 102
Building a Tree
E i
sp
4
e
8
2
y l
2
k .
2
r s
4
n a
4
C#ODE Studio
CS 102
Building a Tree
E i
sp
4
e
8
2
y l
2
k .
2
r s
4
n a
4
C#ODE Studio
CS 102
Building a Tree
E i
sp
4
e
8
2
y l
2
k .
2
r s
4
n a
4
4
C#ODE Studio
CS 102
Building a Tree
E i
sp
4
e
82
y l
2
k .
2
r s
4
n a
4 4
C#ODE Studio
CS 102
Building a Tree
E i
sp
e
82
y l
2
k .
2
r s
4
n a
4 4
6
C#ODE Studio
CS 102
Building a Tree
E i
sp
e
8
2
y l
2
k .
2
r s
4
n a
4 4 6
What is happening to the characters
with a low number of occurrences?
C#ODE Studio
CS 102
Building a Tree
E i
sp
e
82
y l
2
k .
2
r s
4
n a
4
4
6
8
C#ODE Studio
CS 102
Building a Tree
E i
sp
e
82
y l
2
k .
2
r s
4
n a
4
4
6 8
C#ODE Studio
CS 102
Building a Tree
E i
sp
e
8
2
y l
2
k .
2
r s
4
n a
4
4
6
8
10
C#ODE Studio
CS 102
Building a Tree
E i
sp
e
8
2
y l
2
k .
2r s
4
n a
4 4
6
8 10
C#ODE Studio
CS 102
Building a Tree
E i
sp
e2
y l
2
k .
2
r s
4
n a
4
4
6
8
10
16
C#ODE Studio
CS 102
Building a Tree
E i
sp
e
2
y l
2
k .
2
r s
4
n a
4
4
6
8
10 16
C#ODE Studio
CS 102
Building a Tree
E i
sp
e
2
y l
2
k .
2
r s
4
n a
4
4
6
8
10
16
26
C#ODE Studio
CS 102
Building a Tree
E i
sp
e
2
y l
2
k .
2
r s
4
n a
4
4
6
8
10
16
26
•After
enqueueing
this node
there is only
one node left
in priority
queue.
C#ODE Studio
CS 102
Building a Tree
Dequeue the single node
left in the queue.
This tree contains the
new code words for each
character.
Frequency of root node
should equal number of
characters in text.
E i
sp
e
2
y l
2
k .
2
r s
4
n a
4
4
6 8
10
16
26
Eerie eyes seen near lake. 26 characters
C#ODE Studio
CS 102
Encoding the File
Traverse Tree for Codes
• Perform a traversal
of the tree to
obtain new code
words
• Going left is a 0
going right is a 1
• code word is only
completed when a
leaf node is
reached
E i
sp
e
2
y l
2
k .
2
r s
4
n a
4
4
6 8
10
16
26
C#ODE Studio
CS 102
Encoding the File
Traverse Tree for Codes
Char Code
E 0000
i 0001
y 0010
l 0011
k 0100
. 0101
space 011
e 10
r 1100
s 1101
n 1110
a 1111
E i
sp
e
2
y l
2
k .
2
r s
4
n a
4
4
6 8
10
16
26
C#ODE Studio
CS 102
Encoding the File
• Rescan text and
encode file using
new code words
Eerie eyes seen near lake.
Char Code
E 0000
i 0001
y 0010
l 0011
k 0100
. 0101
space 011
e 10
r 1100
s 1101
n 1110
a 1111
0000101100000110011
1000101011011010011
1110101111110001100
1111110100100101
• Why is there no need
for a separator
character?
.
C#ODE Studio
CS 102
Encoding the File
Results
• Have we made
things any
better?
• 73 bits to encode
the text
• ASCII would take
8 * 26 = 208 bits
0000101100000110011
1000101011011010011
1110101111110001100
1111110100100101
If modified code used 4 bits per
character are needed. Total bits
4 * 26 = 104. Savings not as great.
C#ODE Studio
CS 102
Decoding the File
• How does receiver know what the codes are?
• Tree constructed for each text file.
– Considers frequency for each file
– Big hit on compression, especially for smaller
files
• Tree predetermined
– based on statistical analysis of text files or
file types
• Data transmission is bit based versus byte
based
C#ODE Studio
CS 102
Decoding the File
• Once receiver has
tree it scans
incoming bit stream
• 0 ⇒ go left
• 1 ⇒ go right
E i
sp
e
2
y l
2
k .
2
r s
4
n a
4
4
6 8
10
16
26
101000110111101111
01111110000110101
C#ODE Studio
CS 102
Summary
• Huffman coding is a technique
used to compress files for
transmission
• Uses statistical coding
– more frequently used symbols have
shorter code words
• Works well for text and fax
transmissions
• An application that uses several
data structures

More Related Content

What's hot

Huffman Coding Algorithm Presentation
Huffman Coding Algorithm PresentationHuffman Coding Algorithm Presentation
Huffman Coding Algorithm Presentation
Akm Monir
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
shashidharPapishetty
 
Huffman Algorithm and its Application by Ekansh Agarwal
Huffman Algorithm and its Application by Ekansh AgarwalHuffman Algorithm and its Application by Ekansh Agarwal
Huffman Algorithm and its Application by Ekansh Agarwal
Ekansh Agarwal
 
Neural network & its applications
Neural network & its applications Neural network & its applications
Neural network & its applications
Ahmed_hashmi
 
Classical Encryption Techniques
Classical Encryption TechniquesClassical Encryption Techniques
Classical Encryption Techniques
university of education,Lahore
 
Brute force-algorithm
Brute force-algorithmBrute force-algorithm
Brute force-algorithm
9854098540
 
Strassen's matrix multiplication
Strassen's matrix multiplicationStrassen's matrix multiplication
Strassen's matrix multiplication
Megha V
 
Huffman's algorithm in Data Structure
 Huffman's algorithm in Data Structure Huffman's algorithm in Data Structure
Huffman's algorithm in Data Structure
Vrushali Dhanokar
 
Machine Learning with Decision trees
Machine Learning with Decision treesMachine Learning with Decision trees
Machine Learning with Decision trees
Knoldus Inc.
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
Akhil Kaushik
 
Soft computing
Soft computingSoft computing
Soft computing
ganeshpaul6
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to Cryptography
Md. Afif Al Mamun
 
Cryptography
CryptographyCryptography
Cryptography
Sidharth Mohapatra
 
Artificial neural network
Artificial neural networkArtificial neural network
Artificial neural network
mustafa aadel
 
The origin and evaluation criteria of aes
The origin and evaluation criteria of aesThe origin and evaluation criteria of aes
The origin and evaluation criteria of aes
MDKAWSARAHMEDSAGAR
 
Convolution Codes
Convolution CodesConvolution Codes
Convolution Codes
Pratishtha Ram
 
Backpropagation in Convolutional Neural Network
Backpropagation in Convolutional Neural NetworkBackpropagation in Convolutional Neural Network
Backpropagation in Convolutional Neural Network
Hiroshi Kuwajima
 
backpropagation in neural networks
backpropagation in neural networksbackpropagation in neural networks
backpropagation in neural networks
Akash Goel
 
Introduction to Deep Learning
Introduction to Deep LearningIntroduction to Deep Learning
Introduction to Deep Learning
Oswald Campesato
 
Deep Feed Forward Neural Networks and Regularization
Deep Feed Forward Neural Networks and RegularizationDeep Feed Forward Neural Networks and Regularization
Deep Feed Forward Neural Networks and Regularization
Yan Xu
 

What's hot (20)

Huffman Coding Algorithm Presentation
Huffman Coding Algorithm PresentationHuffman Coding Algorithm Presentation
Huffman Coding Algorithm Presentation
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
 
Huffman Algorithm and its Application by Ekansh Agarwal
Huffman Algorithm and its Application by Ekansh AgarwalHuffman Algorithm and its Application by Ekansh Agarwal
Huffman Algorithm and its Application by Ekansh Agarwal
 
Neural network & its applications
Neural network & its applications Neural network & its applications
Neural network & its applications
 
Classical Encryption Techniques
Classical Encryption TechniquesClassical Encryption Techniques
Classical Encryption Techniques
 
Brute force-algorithm
Brute force-algorithmBrute force-algorithm
Brute force-algorithm
 
Strassen's matrix multiplication
Strassen's matrix multiplicationStrassen's matrix multiplication
Strassen's matrix multiplication
 
Huffman's algorithm in Data Structure
 Huffman's algorithm in Data Structure Huffman's algorithm in Data Structure
Huffman's algorithm in Data Structure
 
Machine Learning with Decision trees
Machine Learning with Decision treesMachine Learning with Decision trees
Machine Learning with Decision trees
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Soft computing
Soft computingSoft computing
Soft computing
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to Cryptography
 
Cryptography
CryptographyCryptography
Cryptography
 
Artificial neural network
Artificial neural networkArtificial neural network
Artificial neural network
 
The origin and evaluation criteria of aes
The origin and evaluation criteria of aesThe origin and evaluation criteria of aes
The origin and evaluation criteria of aes
 
Convolution Codes
Convolution CodesConvolution Codes
Convolution Codes
 
Backpropagation in Convolutional Neural Network
Backpropagation in Convolutional Neural NetworkBackpropagation in Convolutional Neural Network
Backpropagation in Convolutional Neural Network
 
backpropagation in neural networks
backpropagation in neural networksbackpropagation in neural networks
backpropagation in neural networks
 
Introduction to Deep Learning
Introduction to Deep LearningIntroduction to Deep Learning
Introduction to Deep Learning
 
Deep Feed Forward Neural Networks and Regularization
Deep Feed Forward Neural Networks and RegularizationDeep Feed Forward Neural Networks and Regularization
Deep Feed Forward Neural Networks and Regularization
 

Viewers also liked

Huffman coding
Huffman codingHuffman coding
Huffman coding
Bagus Nugroho
 
Dijksatra
DijksatraDijksatra
Dijksatra
Tanmay Baranwal
 
Disk scheduling algorithms
Disk scheduling algorithms Disk scheduling algorithms
Disk scheduling algorithms
Paresh Parmar
 
Disk scheduling
Disk schedulingDisk scheduling
Disk scheduling
Suraj Shukla
 
4.4 external hashing
4.4 external hashing4.4 external hashing
4.4 external hashing
Krish_ver2
 
9 cm402.18
9 cm402.189 cm402.18
9 cm402.18
myrajendra
 
Arrays and addressing modes
Arrays and addressing modesArrays and addressing modes
Arrays and addressing modes
Bilal Amjad
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
Tanmay Baranwal
 
Filehandlinging cp2
Filehandlinging cp2Filehandlinging cp2
Filehandlinging cp2
Tanmay Baranwal
 
Implicit objects advance Java
Implicit objects advance JavaImplicit objects advance Java
Implicit objects advance Java
Darshit Metaliya
 
Translation Lookaside Buffer & Inverted Page Table
Translation Lookaside Buffer & Inverted Page TableTranslation Lookaside Buffer & Inverted Page Table
Translation Lookaside Buffer & Inverted Page Table
Darshit Metaliya
 
Projection of line inclined to both the planes
Projection of line inclined to both the planesProjection of line inclined to both the planes
Projection of line inclined to both the planes
Darshit Metaliya
 
Design Concept software engineering
Design Concept software engineeringDesign Concept software engineering
Design Concept software engineering
Darshit Metaliya
 
Data compression huffman coding algoritham
Data compression huffman coding algorithamData compression huffman coding algoritham
Data compression huffman coding algoritham
Rahul Khanwani
 
Page replacement
Page replacementPage replacement
Page replacement
sashi799
 
Disk scheduling algorithm.52
Disk scheduling algorithm.52Disk scheduling algorithm.52
Disk scheduling algorithm.52
myrajendra
 
Longest Common Subsequence (LCS) Algorithm
Longest Common Subsequence (LCS) AlgorithmLongest Common Subsequence (LCS) Algorithm
Longest Common Subsequence (LCS) Algorithm
Darshit Metaliya
 
Addressing mode of 8051
Addressing mode of 8051Addressing mode of 8051
Addressing mode of 8051
Nitin Ahire
 
Hashing Techniques in Data Structures Part2
Hashing Techniques in Data Structures Part2Hashing Techniques in Data Structures Part2
Hashing Techniques in Data Structures Part2
SHAKOOR AB
 
Huffman Coding
Huffman CodingHuffman Coding
Huffman Coding
Ehtisham Ali
 

Viewers also liked (20)

Huffman coding
Huffman codingHuffman coding
Huffman coding
 
Dijksatra
DijksatraDijksatra
Dijksatra
 
Disk scheduling algorithms
Disk scheduling algorithms Disk scheduling algorithms
Disk scheduling algorithms
 
Disk scheduling
Disk schedulingDisk scheduling
Disk scheduling
 
4.4 external hashing
4.4 external hashing4.4 external hashing
4.4 external hashing
 
9 cm402.18
9 cm402.189 cm402.18
9 cm402.18
 
Arrays and addressing modes
Arrays and addressing modesArrays and addressing modes
Arrays and addressing modes
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
Filehandlinging cp2
Filehandlinging cp2Filehandlinging cp2
Filehandlinging cp2
 
Implicit objects advance Java
Implicit objects advance JavaImplicit objects advance Java
Implicit objects advance Java
 
Translation Lookaside Buffer & Inverted Page Table
Translation Lookaside Buffer & Inverted Page TableTranslation Lookaside Buffer & Inverted Page Table
Translation Lookaside Buffer & Inverted Page Table
 
Projection of line inclined to both the planes
Projection of line inclined to both the planesProjection of line inclined to both the planes
Projection of line inclined to both the planes
 
Design Concept software engineering
Design Concept software engineeringDesign Concept software engineering
Design Concept software engineering
 
Data compression huffman coding algoritham
Data compression huffman coding algorithamData compression huffman coding algoritham
Data compression huffman coding algoritham
 
Page replacement
Page replacementPage replacement
Page replacement
 
Disk scheduling algorithm.52
Disk scheduling algorithm.52Disk scheduling algorithm.52
Disk scheduling algorithm.52
 
Longest Common Subsequence (LCS) Algorithm
Longest Common Subsequence (LCS) AlgorithmLongest Common Subsequence (LCS) Algorithm
Longest Common Subsequence (LCS) Algorithm
 
Addressing mode of 8051
Addressing mode of 8051Addressing mode of 8051
Addressing mode of 8051
 
Hashing Techniques in Data Structures Part2
Hashing Techniques in Data Structures Part2Hashing Techniques in Data Structures Part2
Hashing Techniques in Data Structures Part2
 
Huffman Coding
Huffman CodingHuffman Coding
Huffman Coding
 

Similar to Huffman

CS-102 Data Structures huffman coding.pdf
CS-102 Data Structures huffman coding.pdfCS-102 Data Structures huffman coding.pdf
CS-102 Data Structures huffman coding.pdf
ssuser034ce1
 
CS-102 Data Structures huffman coding.pdf
CS-102 Data Structures huffman coding.pdfCS-102 Data Structures huffman coding.pdf
CS-102 Data Structures huffman coding.pdf
ssuser034ce1
 
Huffman Tree And Its Application
Huffman Tree And Its ApplicationHuffman Tree And Its Application
Huffman Tree And Its Application
Papu Kumar
 
Huffman
HuffmanHuffman
Huffman1
Huffman1Huffman1
Huffman 2
Huffman 2Huffman 2
Huffman 2
grupo6tic
 
Data Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding AlgorithmData Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding Algorithm
ManishPrajapati78
 
Huffman > Data Structures & Algorithums
Huffman > Data Structures & AlgorithumsHuffman > Data Structures & Algorithums
Huffman > Data Structures & Algorithums
Ain-ul-Moiz Khawaja
 
Data compession
Data compession Data compession
Data compession
arvind carpenter
 
huffman algoritm upload for understand.ppt
huffman algoritm upload for understand.ppthuffman algoritm upload for understand.ppt
huffman algoritm upload for understand.ppt
SadiaSharmin40
 
huffman codes and algorithm
huffman codes and algorithm huffman codes and algorithm
huffman codes and algorithm
Vinay379568
 
huffman_nyu.ppt ghgghtttjghh hhhhhhhhhhh
huffman_nyu.ppt ghgghtttjghh hhhhhhhhhhhhuffman_nyu.ppt ghgghtttjghh hhhhhhhhhhh
huffman_nyu.ppt ghgghtttjghh hhhhhhhhhhh
BARUNSINGH43
 
Huffman
HuffmanHuffman
Huffman.pptx
Huffman.pptxHuffman.pptx
Huffman.pptx
HarisMasood20
 
Farhana shaikh webinar_huffman coding
Farhana shaikh webinar_huffman codingFarhana shaikh webinar_huffman coding
Farhana shaikh webinar_huffman coding
Farhana Shaikh
 
Cassandra for the ops dos and donts
Cassandra for the ops   dos and dontsCassandra for the ops   dos and donts
Cassandra for the ops dos and donts
Duyhai Doan
 
Huffman tree
Huffman tree Huffman tree
Huffman tree
Al-amin Hossain
 
Cassandra introduction mars jug
Cassandra introduction mars jugCassandra introduction mars jug
Cassandra introduction mars jug
Duyhai Doan
 
Huffman Codes
Huffman CodesHuffman Codes
Huffman Codes
Md. Shafiuzzaman Hira
 
Creating a Fibonacci Generator in Assembly - by Willem van Ketwich
Creating a Fibonacci Generator in Assembly - by Willem van KetwichCreating a Fibonacci Generator in Assembly - by Willem van Ketwich
Creating a Fibonacci Generator in Assembly - by Willem van Ketwich
Willem van Ketwich
 

Similar to Huffman (20)

CS-102 Data Structures huffman coding.pdf
CS-102 Data Structures huffman coding.pdfCS-102 Data Structures huffman coding.pdf
CS-102 Data Structures huffman coding.pdf
 
CS-102 Data Structures huffman coding.pdf
CS-102 Data Structures huffman coding.pdfCS-102 Data Structures huffman coding.pdf
CS-102 Data Structures huffman coding.pdf
 
Huffman Tree And Its Application
Huffman Tree And Its ApplicationHuffman Tree And Its Application
Huffman Tree And Its Application
 
Huffman
HuffmanHuffman
Huffman
 
Huffman1
Huffman1Huffman1
Huffman1
 
Huffman 2
Huffman 2Huffman 2
Huffman 2
 
Data Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding AlgorithmData Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding Algorithm
 
Huffman > Data Structures & Algorithums
Huffman > Data Structures & AlgorithumsHuffman > Data Structures & Algorithums
Huffman > Data Structures & Algorithums
 
Data compession
Data compession Data compession
Data compession
 
huffman algoritm upload for understand.ppt
huffman algoritm upload for understand.ppthuffman algoritm upload for understand.ppt
huffman algoritm upload for understand.ppt
 
huffman codes and algorithm
huffman codes and algorithm huffman codes and algorithm
huffman codes and algorithm
 
huffman_nyu.ppt ghgghtttjghh hhhhhhhhhhh
huffman_nyu.ppt ghgghtttjghh hhhhhhhhhhhhuffman_nyu.ppt ghgghtttjghh hhhhhhhhhhh
huffman_nyu.ppt ghgghtttjghh hhhhhhhhhhh
 
Huffman
HuffmanHuffman
Huffman
 
Huffman.pptx
Huffman.pptxHuffman.pptx
Huffman.pptx
 
Farhana shaikh webinar_huffman coding
Farhana shaikh webinar_huffman codingFarhana shaikh webinar_huffman coding
Farhana shaikh webinar_huffman coding
 
Cassandra for the ops dos and donts
Cassandra for the ops   dos and dontsCassandra for the ops   dos and donts
Cassandra for the ops dos and donts
 
Huffman tree
Huffman tree Huffman tree
Huffman tree
 
Cassandra introduction mars jug
Cassandra introduction mars jugCassandra introduction mars jug
Cassandra introduction mars jug
 
Huffman Codes
Huffman CodesHuffman Codes
Huffman Codes
 
Creating a Fibonacci Generator in Assembly - by Willem van Ketwich
Creating a Fibonacci Generator in Assembly - by Willem van KetwichCreating a Fibonacci Generator in Assembly - by Willem van Ketwich
Creating a Fibonacci Generator in Assembly - by Willem van Ketwich
 

Recently uploaded

CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
rpskprasana
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
HODECEDSIET
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
mamamaam477
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
sachin chaurasia
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
NazakatAliKhoso2
 

Recently uploaded (20)

CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
 

Huffman

  • 1. C#ODE Studio CS 102 Huffman Coding: An Application of Binary Trees and Priority Queues
  • 2. C#ODE Studio CS 102 Encoding and Compression of Data • Fax Machines • ASCII • Variations on ASCII – min number of bits needed – cost of savings – patterns – modifications
  • 3. C#ODE Studio CS 102 Purpose of Huffman Coding • Proposed by Dr. David A. Huffman in 1952 – “A Method for the Construction of Minimum Redundancy Codes” • Applicable to many forms of data transmission – Our example: text files
  • 4. C#ODE Studio CS 102 The Basic Algorithm • 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 – 1 char = 1 byte, be it e or x
  • 5. C#ODE Studio CS 102 The Basic Algorithm • Any savings in tailoring codes to frequency of character? • Code word lengths are no longer fixed like ASCII. • Code word lengths vary and will be shorter for the more frequently used characters.
  • 6. C#ODE Studio CS 102 The (Real) Basic Algorithm 1. Scan text to be compressed and tally occurrence of all characters. 2. Sort or prioritize characters based on number of occurrences in text. 3. Build Huffman code tree based on prioritized list. 4. Perform a traversal of tree to determine all code words. 5. Scan text again and create new file using the Huffman codes.
  • 7. C#ODE Studio CS 102 Building a Tree Scan the original text • Consider the following short text: Eerie eyes seen near lake. • Count up the occurrences of all characters in the text
  • 8. C#ODE Studio CS 102 Building a Tree Scan the original text Eerie eyes seen near lake. • What characters are present? E e r i space y s n a r l k .
  • 9. C#ODE Studio CS 102 Building a Tree Scan the original text Eerie eyes seen near lake. • What is the frequency of each character in the text? Char Freq. Char Freq. Char Freq. E 1 y 1 k 1 e 8 s 2 . 1 r 2 n 2 i 1 a 2 space 4 l 1
  • 10. C#ODE Studio CS 102 Building a Tree Prioritize characters • Create binary tree nodes with character and frequency of each character • Place nodes in a priority queue – The lower the occurrence, the higher the priority in the queue
  • 11. C#ODE Studio CS 102 Building a Tree Prioritize characters • Uses binary tree nodes public class HuffNode { public char myChar; public int myFrequency; public HuffNode myLeft, myRight; } priorityQueue myQueue;
  • 12. C#ODE Studio CS 102 Building a Tree • The queue after inserting all nodes • Null Pointers are not shown E 1 i 1 y 1 l 1 k 1 . 1 r 2 s 2 n 2 a 2 sp 4 e 8
  • 13. C#ODE Studio CS 102 Building a Tree • While priority queue contains two or more nodes – Create new node – Dequeue node and make it left subtree – Dequeue next node and make it right subtree – Frequency of new node equals sum of frequency of left and right children – Enqueue new node back into queue
  • 14. C#ODE Studio CS 102 Building a Tree E 1 i 1 y 1 l 1 k 1 . 1 r 2 s 2 n 2 a 2 sp 4 e 8
  • 15. C#ODE Studio CS 102 Building a Tree E i y 1 l 1 k 1 . 1 r 2 s 2 n 2 a 2 sp 4 e 8 2
  • 16. C#ODE Studio CS 102 Building a Tree E i y 1 l 1 k 1 . 1 r 2 s 2 n 2 a 2 sp 4 e 8
  • 17. C#ODE Studio CS 102 Building a Tree E i k 1 . 1 r 2 s 2 n 2 a 2 sp 4 e 8 y l
  • 18. C#ODE Studio CS 102 Building a Tree E i k 1 . 1 r 2 s 2 n 2 a 2 sp 4 e 8 2 y l 2
  • 19. C#ODE Studio CS 102 Building a Tree E i r 2 s 2 n 2 a 2 sp 4 e 8 2 y l 2 k . 2
  • 20. C#ODE Studio CS 102 Building a Tree E i r 2 s 2 n 2 a 2 sp 4 e 8 2 y l 2 k . 2
  • 21. C#ODE Studio CS 102 Building a Tree E i n 2 a 2 sp 4 e 8 2 y l 2 k . 2 r s 4
  • 22. C#ODE Studio CS 102 Building a Tree E i n 2 a 2 sp 4 e 8 2 y l 2 k . 2 r s 4
  • 23. C#ODE Studio CS 102 Building a Tree E i sp 4 e 8 2 y l 2 k . 2 r s 4 n a 4
  • 24. C#ODE Studio CS 102 Building a Tree E i sp 4 e 8 2 y l 2 k . 2 r s 4 n a 4
  • 25. C#ODE Studio CS 102 Building a Tree E i sp 4 e 8 2 y l 2 k . 2 r s 4 n a 4 4
  • 26. C#ODE Studio CS 102 Building a Tree E i sp 4 e 82 y l 2 k . 2 r s 4 n a 4 4
  • 27. C#ODE Studio CS 102 Building a Tree E i sp e 82 y l 2 k . 2 r s 4 n a 4 4 6
  • 28. C#ODE Studio CS 102 Building a Tree E i sp e 8 2 y l 2 k . 2 r s 4 n a 4 4 6 What is happening to the characters with a low number of occurrences?
  • 29. C#ODE Studio CS 102 Building a Tree E i sp e 82 y l 2 k . 2 r s 4 n a 4 4 6 8
  • 30. C#ODE Studio CS 102 Building a Tree E i sp e 82 y l 2 k . 2 r s 4 n a 4 4 6 8
  • 31. C#ODE Studio CS 102 Building a Tree E i sp e 8 2 y l 2 k . 2 r s 4 n a 4 4 6 8 10
  • 32. C#ODE Studio CS 102 Building a Tree E i sp e 8 2 y l 2 k . 2r s 4 n a 4 4 6 8 10
  • 33. C#ODE Studio CS 102 Building a Tree E i sp e2 y l 2 k . 2 r s 4 n a 4 4 6 8 10 16
  • 34. C#ODE Studio CS 102 Building a Tree E i sp e 2 y l 2 k . 2 r s 4 n a 4 4 6 8 10 16
  • 35. C#ODE Studio CS 102 Building a Tree E i sp e 2 y l 2 k . 2 r s 4 n a 4 4 6 8 10 16 26
  • 36. C#ODE Studio CS 102 Building a Tree E i sp e 2 y l 2 k . 2 r s 4 n a 4 4 6 8 10 16 26 •After enqueueing this node there is only one node left in priority queue.
  • 37. C#ODE Studio CS 102 Building a Tree Dequeue the single node left in the queue. This tree contains the new code words for each character. Frequency of root node should equal number of characters in text. E i sp e 2 y l 2 k . 2 r s 4 n a 4 4 6 8 10 16 26 Eerie eyes seen near lake. 26 characters
  • 38. C#ODE Studio CS 102 Encoding the File Traverse Tree for Codes • Perform a traversal of the tree to obtain new code words • Going left is a 0 going right is a 1 • code word is only completed when a leaf node is reached E i sp e 2 y l 2 k . 2 r s 4 n a 4 4 6 8 10 16 26
  • 39. C#ODE Studio CS 102 Encoding the File Traverse Tree for Codes Char Code E 0000 i 0001 y 0010 l 0011 k 0100 . 0101 space 011 e 10 r 1100 s 1101 n 1110 a 1111 E i sp e 2 y l 2 k . 2 r s 4 n a 4 4 6 8 10 16 26
  • 40. C#ODE Studio CS 102 Encoding the File • Rescan text and encode file using new code words Eerie eyes seen near lake. Char Code E 0000 i 0001 y 0010 l 0011 k 0100 . 0101 space 011 e 10 r 1100 s 1101 n 1110 a 1111 0000101100000110011 1000101011011010011 1110101111110001100 1111110100100101 • Why is there no need for a separator character? .
  • 41. C#ODE Studio CS 102 Encoding the File Results • Have we made things any better? • 73 bits to encode the text • ASCII would take 8 * 26 = 208 bits 0000101100000110011 1000101011011010011 1110101111110001100 1111110100100101 If modified code used 4 bits per character are needed. Total bits 4 * 26 = 104. Savings not as great.
  • 42. C#ODE Studio CS 102 Decoding the File • How does receiver know what the codes are? • Tree constructed for each text file. – Considers frequency for each file – Big hit on compression, especially for smaller files • Tree predetermined – based on statistical analysis of text files or file types • Data transmission is bit based versus byte based
  • 43. C#ODE Studio CS 102 Decoding the File • Once receiver has tree it scans incoming bit stream • 0 ⇒ go left • 1 ⇒ go right E i sp e 2 y l 2 k . 2 r s 4 n a 4 4 6 8 10 16 26 101000110111101111 01111110000110101
  • 44. C#ODE Studio CS 102 Summary • Huffman coding is a technique used to compress files for transmission • Uses statistical coding – more frequently used symbols have shorter code words • Works well for text and fax transmissions • An application that uses several data structures