SlideShare a Scribd company logo
4
Most read
5
Most read
9
Most read
Huffman Coding
bY P.GuruNadh
IIIT SRIKAKULAM
Huffman Coding
● Huffman coding is proposed by David A. Huffman in 1952
● It is the one of the application of Binary Search Trees.
● It is Used for compression of Files.
● Compression is Nothing but reducing the size.
● We use this Huffman coding in WinRar,WinZip,7zip Applications etc..,
Huffman Tree
● It is used for to give unique encoding to a particular code or string
● Properties Of Huffman Tree
○ It should contain root node
○ Internal nodes are indicated with circles( ) and it should contain weights.
○ External nodes are indicated with squares( )and they should contain Frequency &
Characters.
Normal Encoding
● Let we take an example
● Let there are 7 characters in a string and each character is represented in 8
bits(ASCII CODES)
ASCII
a-97
b-98
c-100
d-101
BINARY(8 bits)
a-01100001
b-01100010
c-01100011
d-01100100
For representing abcdaab we need 7*8=56 bits
To reduce the bits we go for frequent characters.
Binary Encoding Representation
a b c d
a a b
01100001 01100010 01100011 01100100 01100001 01100001
01100001 01100010
Frequent Characters Technique
● In frequent characters technique the frequent occur character will take less bits and
rarely occur character will take large bits.
⮚ Let’s take the previous example , in this method we first calculate frequency of
characters.
⮚ Highest frequency character is represented with less bits and lowest frequency
character is represented with large bits.
Representation
a-0
b-10
c-110
d-111
By this technique for representing abcdaab we
need only 13 bits.
a b c d
a a b
0 10 110 111
0 0 10
Construction Of Huffman Tree
1.Scan text to be compressed and count occurrence of all characters.
2.Sort characters based on number of occurrences in text.
3.Take 2 characters which are having least frequency as leaf nodes.
4.And sum the data of that nodes and take it as it’s parent node.
5.Take next least occurred node and compare with parent node.
6.If compared node > parent node place at right side of parent node.
7.Else place at left side of parent node and repeat the procedure from step 4.
8.Perform a traversal of tree to determine all code words.
Huffman Tree Logic
HT( )
{
N=Priority Queue ;
Sort(N);
for(i=1 to n-1)
{
create_Node; //Z
Z.left = min(Z);
Z.right = Next_min(N);
Z.frequency=Z.left + Z.right;
push(z.frequency)
}
}
Key words of Huffman Tree
● Internal path length
○ The longest path from root node to corresponding internal node.
● External path length
○ The longest path from root node to corresponding external node.
● Let n be the number of internal nodes then,
○ External path length = Internal path length+2*n
● External weighted nodes = External path length * Frequency of External Node
● Sum of External weighted nodes = storage
Examples
● String = ab ab cba ; Occurrences = a🡪3;b🡪3;c🡪1;space🡪2;eof🡪1;
1 1
c
eof
🡪
2
1 1
c
eof
🡪
2
1 1
c
eof
2 2
1
Space
c,eof=1;space=2;a,b=3
Continue….
Continue…..
1
c
eof
2 2
1
Space
4
🡪
1
c
eof
2 2
1
Space
4
🡪
1
c
eof
2 2
1
Space
4
3
a
Continue…
● Continue…..
1
c
eof
2 2
1
Space
43
1
c
eof
2 2
1
Space
43
🡪
7
a a 🡪
1
c
eof
2 2
Space
43
7
a
1
b
3
Continue..
● Encode with 0’s at left side and 1’s at right side nodes of every parent node to get the representation
of characters in bits.
🡪
10
0
1
Representation
b-0
a-10
c-1100
Space-111
eof-1101
Calculations For Example
● For Previous Example Huffman tree
● Internal Length = Sum of Internal Lengths of internal nodes
○ 1(7)+2(4)+3(2)+0(10)=6
● External length = Sum of External Lengths of External nodes
○ 4(c)+4(eof)+3(space)+2(a)+1(b)=14
● Storage = sum of weighted external nodes = sum of(external path
length*frequency)
○ (4*1)+(4*1)+(3*2)+(2*3)+(1*3) = 23
10,7,4,2 Are Internal Nodes
c,eof,space,a,b Are External
Nodes
1,1,2,3,3 Are Frequencies Of
External Nodes
Any Queries….?
Mail to:-
-S160552@rguktsklm.ac.in

More Related Content

What's hot (20)

PPTX
Digital to Analog conversion
Mariam Butt
 
PPTX
Huffman coding || Huffman Tree
SatishKumarInumarthi
 
PPTX
NYQUIST CRITERION FOR ZERO ISI
FAIZAN SHAFI
 
PPTX
Windowing techniques of fir filter design
Rohan Nagpal
 
PPTX
Array multiplier
Mathew George
 
PPTX
Differential pulse code modulation
Ramraj Bhadu
 
PPTX
Principal Sources of Optimization in compiler design
LogsAk
 
PDF
8155 PPI
ShivamSood22
 
PPTX
Time Division Multiplexing
Md. Hasan Imam Bijoy
 
PPTX
Log periodic antenna
Keval Patel
 
PPTX
Huffman Coding Algorithm Presentation
Akm Monir
 
PPTX
Representation of signals
Mehedi Hasan Raju
 
PPT
Speech encoding techniques
Hemaraja Nayaka S
 
PPTX
Digital Electronics - Counters
Jayakrishnan J
 
PPTX
DIGITAL COMMUNICATION: ENCODING AND DECODING OF CYCLIC CODE
ShivangiSingh241
 
PDF
Classical Encryption Techniques.pdf
DevangShukla10
 
PPTX
Digital communication unit II
Gangatharan Narayanan
 
PDF
Intermediate code generation in Compiler Design
Kuppusamy P
 
PPTX
Huffman Coding
Muhammad Saqib Rehan
 
PDF
8086 memory segmentation
mahalakshmimalini
 
Digital to Analog conversion
Mariam Butt
 
Huffman coding || Huffman Tree
SatishKumarInumarthi
 
NYQUIST CRITERION FOR ZERO ISI
FAIZAN SHAFI
 
Windowing techniques of fir filter design
Rohan Nagpal
 
Array multiplier
Mathew George
 
Differential pulse code modulation
Ramraj Bhadu
 
Principal Sources of Optimization in compiler design
LogsAk
 
8155 PPI
ShivamSood22
 
Time Division Multiplexing
Md. Hasan Imam Bijoy
 
Log periodic antenna
Keval Patel
 
Huffman Coding Algorithm Presentation
Akm Monir
 
Representation of signals
Mehedi Hasan Raju
 
Speech encoding techniques
Hemaraja Nayaka S
 
Digital Electronics - Counters
Jayakrishnan J
 
DIGITAL COMMUNICATION: ENCODING AND DECODING OF CYCLIC CODE
ShivangiSingh241
 
Classical Encryption Techniques.pdf
DevangShukla10
 
Digital communication unit II
Gangatharan Narayanan
 
Intermediate code generation in Compiler Design
Kuppusamy P
 
Huffman Coding
Muhammad Saqib Rehan
 
8086 memory segmentation
mahalakshmimalini
 

Similar to Huffman coding || Huffman Tree (20)

PDF
j001adcpresentation-2112170415 23.pdf
HarshSharma71048
 
PPTX
Huffman Algorithm and its Application by Ekansh Agarwal
Ekansh Agarwal
 
PDF
Huffman Encoding Algorithm - Concepts and Example
MaryJacob24
 
PPTX
5c. huffman coding using greedy technique.pptx
Suma Raj
 
PDF
DSA Presentetion Huffman tree.pdf
GaneshPawar819187
 
PPTX
DAA PPT.pptx
SintooChauhan6
 
PPTX
Huffman Codes
Md. Shafiuzzaman Hira
 
PDF
Huffman
keerthi vasan
 
PDF
Huffman
keerthi vasan
 
PPT
Greedy Algorithms Huffman Coding.ppt
Ruchika Sinha
 
PPTX
t.pptx hd gsd unduf jdsnfijnfi bndsfuu ubfuh
chouhangulbadansing
 
PPTX
Data Structures and Agorithm: DS 16 Huffman Coding.pptx
RashidFaridChishti
 
PPTX
Huffman.Encodingpptx Variable length coding
zeeshanmubeen1
 
PPTX
Huffman's algorithm in Data Structure
Vrushali Dhanokar
 
PDF
Adaptive huffman coding
Burqaa Hundeessaa
 
PPTX
Huffman's Alforithm
Roohaali
 
DOCX
Huffman Coding is a technique of compressing data
Kumari99
 
DOC
Huffman coding01
Nv Thejaswini
 
DOC
HuffmanCoding01.doc
Qwertty3
 
PPT
Huffman coding presentation Sukkur iba.ppt
FarhanAli766749
 
j001adcpresentation-2112170415 23.pdf
HarshSharma71048
 
Huffman Algorithm and its Application by Ekansh Agarwal
Ekansh Agarwal
 
Huffman Encoding Algorithm - Concepts and Example
MaryJacob24
 
5c. huffman coding using greedy technique.pptx
Suma Raj
 
DSA Presentetion Huffman tree.pdf
GaneshPawar819187
 
DAA PPT.pptx
SintooChauhan6
 
Huffman Codes
Md. Shafiuzzaman Hira
 
Huffman
keerthi vasan
 
Huffman
keerthi vasan
 
Greedy Algorithms Huffman Coding.ppt
Ruchika Sinha
 
t.pptx hd gsd unduf jdsnfijnfi bndsfuu ubfuh
chouhangulbadansing
 
Data Structures and Agorithm: DS 16 Huffman Coding.pptx
RashidFaridChishti
 
Huffman.Encodingpptx Variable length coding
zeeshanmubeen1
 
Huffman's algorithm in Data Structure
Vrushali Dhanokar
 
Adaptive huffman coding
Burqaa Hundeessaa
 
Huffman's Alforithm
Roohaali
 
Huffman Coding is a technique of compressing data
Kumari99
 
Huffman coding01
Nv Thejaswini
 
HuffmanCoding01.doc
Qwertty3
 
Huffman coding presentation Sukkur iba.ppt
FarhanAli766749
 
Ad

Recently uploaded (20)

PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
community health nursing question paper 2.pdf
Prince kumar
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Ad

Huffman coding || Huffman Tree

  • 2. Huffman Coding ● Huffman coding is proposed by David A. Huffman in 1952 ● It is the one of the application of Binary Search Trees. ● It is Used for compression of Files. ● Compression is Nothing but reducing the size. ● We use this Huffman coding in WinRar,WinZip,7zip Applications etc..,
  • 3. Huffman Tree ● It is used for to give unique encoding to a particular code or string ● Properties Of Huffman Tree ○ It should contain root node ○ Internal nodes are indicated with circles( ) and it should contain weights. ○ External nodes are indicated with squares( )and they should contain Frequency & Characters.
  • 4. Normal Encoding ● Let we take an example ● Let there are 7 characters in a string and each character is represented in 8 bits(ASCII CODES) ASCII a-97 b-98 c-100 d-101 BINARY(8 bits) a-01100001 b-01100010 c-01100011 d-01100100 For representing abcdaab we need 7*8=56 bits To reduce the bits we go for frequent characters. Binary Encoding Representation a b c d a a b 01100001 01100010 01100011 01100100 01100001 01100001 01100001 01100010
  • 5. Frequent Characters Technique ● In frequent characters technique the frequent occur character will take less bits and rarely occur character will take large bits. ⮚ Let’s take the previous example , in this method we first calculate frequency of characters. ⮚ Highest frequency character is represented with less bits and lowest frequency character is represented with large bits. Representation a-0 b-10 c-110 d-111 By this technique for representing abcdaab we need only 13 bits. a b c d a a b 0 10 110 111 0 0 10
  • 6. Construction Of Huffman Tree 1.Scan text to be compressed and count occurrence of all characters. 2.Sort characters based on number of occurrences in text. 3.Take 2 characters which are having least frequency as leaf nodes. 4.And sum the data of that nodes and take it as it’s parent node. 5.Take next least occurred node and compare with parent node. 6.If compared node > parent node place at right side of parent node. 7.Else place at left side of parent node and repeat the procedure from step 4. 8.Perform a traversal of tree to determine all code words.
  • 7. Huffman Tree Logic HT( ) { N=Priority Queue ; Sort(N); for(i=1 to n-1) { create_Node; //Z Z.left = min(Z); Z.right = Next_min(N); Z.frequency=Z.left + Z.right; push(z.frequency) } }
  • 8. Key words of Huffman Tree ● Internal path length ○ The longest path from root node to corresponding internal node. ● External path length ○ The longest path from root node to corresponding external node. ● Let n be the number of internal nodes then, ○ External path length = Internal path length+2*n ● External weighted nodes = External path length * Frequency of External Node ● Sum of External weighted nodes = storage
  • 9. Examples ● String = ab ab cba ; Occurrences = a🡪3;b🡪3;c🡪1;space🡪2;eof🡪1; 1 1 c eof 🡪 2 1 1 c eof 🡪 2 1 1 c eof 2 2 1 Space c,eof=1;space=2;a,b=3
  • 11. Continue… ● Continue….. 1 c eof 2 2 1 Space 43 1 c eof 2 2 1 Space 43 🡪 7 a a 🡪 1 c eof 2 2 Space 43 7 a 1 b 3
  • 12. Continue.. ● Encode with 0’s at left side and 1’s at right side nodes of every parent node to get the representation of characters in bits. 🡪 10 0 1 Representation b-0 a-10 c-1100 Space-111 eof-1101
  • 13. Calculations For Example ● For Previous Example Huffman tree ● Internal Length = Sum of Internal Lengths of internal nodes ○ 1(7)+2(4)+3(2)+0(10)=6 ● External length = Sum of External Lengths of External nodes ○ 4(c)+4(eof)+3(space)+2(a)+1(b)=14 ● Storage = sum of weighted external nodes = sum of(external path length*frequency) ○ (4*1)+(4*1)+(3*2)+(2*3)+(1*3) = 23 10,7,4,2 Are Internal Nodes c,eof,space,a,b Are External Nodes 1,1,2,3,3 Are Frequencies Of External Nodes