PRESENTED TO:- DR. M.C.LOHANI
BY:- PAPU KUMAR
SECTION:- B
ROLL NO.:- 2061424(47)
SEMESTER:- III
BRANCH:- C.S.E.
HUffMAN TREE
&
IT’S APPLICATION
Encoding and Compression of
Data
• Fax Machines
• ASCII
• Variations on ASCII
• min number of bits needed
• cost of savings
• patterns
• modifications
Application
• 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
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
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 eor x
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.
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.
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
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 .
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
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
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
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
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
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
Building a Tree
E i
y
1
l
1
k
1
.
1
r
2
s
2
n
2
a
2
sp
4
e
8
Building a Tree
E i
k
1
.
1
r
2
s
2
n
2
a
2
sp
4
e
8
y l
Building a Tree
E i
k
1
.
1
r
2
s
2
n
2
a
2
sp
4
e
8
2
y l
2
Building a Tree
E i
r
2
s
2
n
2
a
2
sp
4
e
8
2
y l
2
k .
2
Building a Tree
E i
r
2
s
2
n
2
a
2
sp
4
e
8
2
y l
2
k .
2
Building a Tree
E i
n
2
a
2
sp
4
e
8
2
y l
2
k .
2
r s
4
Building a Tree
E i
n
2
a
2
sp
4
e
8
2
y l
2
k .
2
r s
4
Building a Tree
E i
sp
4
e
8
2
y l
2
k .
2
r s
4
n a
4
Building a Tree
E i
sp
4
e
8
2
y l
2
k .
2
r s
4
n a
4
Building a Tree
E i
sp
4
e
8
2
y l
2
k .
2
r s
4
n a
4
4
Building a Tree
E i
sp
4
e
82
y l
2
k .
2
r s
4
n a
4 4
Building a Tree
E i
sp
e
82
y l
2
k .
2
r s
4
n a
4 4
6
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?
Building a Tree
E i
sp
e
82
y l
2
k .
2
r s
4
n a
4
4
6
8
Building a Tree
E i
sp
e
82
y l
2
k .
2
r s
4
n a
4
4
6 8
Building a Tree
E i
sp
e
8
2
y l
2
k .
2
r s
4
n a
4
4
6
8
10
Building a Tree
E i
sp
e
8
2
y l
2
k .
2r s
4
n a
4 4
6
8 10
Building a Tree
E i
sp
e2
y l
2
k .
2
r s
4
n a
4
4
6
8
10
16
Building a Tree
E i
sp
e
2
y l
2
k .
2
r s
4
n a
4
4
6
8
10 16
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
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.
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
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
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
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?
.
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.
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
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
The end
Thank

More Related Content

PPTX
Code Optimization
PPTX
Huffman coding
PPTX
Routing algorithm
PPTX
switching techniques in data communication and networking
PPT
Multi Head, Multi Tape Turing Machine
PPTX
Interface specification
PPTX
Voice assistant ppt
PPTX
Code Optimization
Huffman coding
Routing algorithm
switching techniques in data communication and networking
Multi Head, Multi Tape Turing Machine
Interface specification
Voice assistant ppt

What's hot (20)

PPTX
Parsing in Compiler Design
PDF
Lecture Note-1: Algorithm and Its Properties
PPSX
Issues in Data Link Layer
PPTX
Transport layer
PPT
PPT
Network Layer,Computer Networks
PDF
Symbol table in compiler Design
PPTX
Code generation
PPTX
GUI components in Java
PPTX
java mini project for college students
PPT
Domain name system
PPTX
object oriented methodologies
PPT
1.1 The nature of software.ppt
PPTX
Method overloading
PPT
Compiler Design Unit 1
PDF
Operator precedence
PPTX
python project ppt.pptx
PPTX
Compiler construction tools
PPT
Compiler Design Basics
PPTX
Network Layer design Issues.pptx
Parsing in Compiler Design
Lecture Note-1: Algorithm and Its Properties
Issues in Data Link Layer
Transport layer
Network Layer,Computer Networks
Symbol table in compiler Design
Code generation
GUI components in Java
java mini project for college students
Domain name system
object oriented methodologies
1.1 The nature of software.ppt
Method overloading
Compiler Design Unit 1
Operator precedence
python project ppt.pptx
Compiler construction tools
Compiler Design Basics
Network Layer design Issues.pptx
Ad

Viewers also liked (19)

PPTX
Huffman Coding
PPTX
Greedy Algorithm
PDF
Huffman Encoding Pr
PPTX
Huffman tree
PPTX
Huffman coding
PDF
3G Transport Profile
PDF
File compression sunzip (huffman algorithm)
PPT
Hufman coding basic
PPTX
investigación cientifica
PPTX
The new Wilson VH3300 Automated Knoop/Vickers Hardness Tester
PDF
An Essential Relationship between Real-time and Resource Partitioning
PPT
Chapter%202%20 %20 Text%20compression(2)
 
PPTX
Cours4.1 recherche documentaire-outils
PPTX
Cours4.4 google
PPTX
Computer architecture
PPT
0 introduction to computer architecture
PPT
Huffman Coding
PPTX
Memory Organization
PPT
Computer architecture
Huffman Coding
Greedy Algorithm
Huffman Encoding Pr
Huffman tree
Huffman coding
3G Transport Profile
File compression sunzip (huffman algorithm)
Hufman coding basic
investigación cientifica
The new Wilson VH3300 Automated Knoop/Vickers Hardness Tester
An Essential Relationship between Real-time and Resource Partitioning
Chapter%202%20 %20 Text%20compression(2)
 
Cours4.1 recherche documentaire-outils
Cours4.4 google
Computer architecture
0 introduction to computer architecture
Huffman Coding
Memory Organization
Computer architecture
Ad

Similar to Huffman Tree And Its Application (20)

PPT
Huffman > Data Structures & Algorithums
PPT
Data Structure and Algorithms Huffman Coding Algorithm
PDF
CS-102 Data Structures huffman coding.pdf
PPTX
Huffman.pptx
PPT
Huffman 2
PPT
PPT
PPTX
Data compession
PPT
Greedy Algorithms Huffman Coding.ppt
PPT
huffman_nyu.ppt ghgghtttjghh hhhhhhhhhhh
PPT
huffman codes and algorithm
PPT
huffman algoritm upload for understand.ppt
PPT
PPTX
Huffman Codes
PPT
computer notes - Data Structures - 23
PPTX
Data structures' project
PPT
computer notes - Data Structures - 24
PPT
trees.ppt
PPT
Computer notes - Expression Tree
DOC
HuffmanCoding01.doc
Huffman > Data Structures & Algorithums
Data Structure and Algorithms Huffman Coding Algorithm
CS-102 Data Structures huffman coding.pdf
Huffman.pptx
Huffman 2
Data compession
Greedy Algorithms Huffman Coding.ppt
huffman_nyu.ppt ghgghtttjghh hhhhhhhhhhh
huffman codes and algorithm
huffman algoritm upload for understand.ppt
Huffman Codes
computer notes - Data Structures - 23
Data structures' project
computer notes - Data Structures - 24
trees.ppt
Computer notes - Expression Tree
HuffmanCoding01.doc

Recently uploaded (20)

DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PDF
My India Quiz Book_20210205121199924.pdf
DOCX
Cambridge-Practice-Tests-for-IELTS-12.docx
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
Hazard Identification & Risk Assessment .pdf
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PPTX
Introduction to pro and eukaryotes and differences.pptx
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
PPTX
20th Century Theater, Methods, History.pptx
PPTX
TNA_Presentation-1-Final(SAVE)) (1).pptx
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PDF
International_Financial_Reporting_Standa.pdf
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
My India Quiz Book_20210205121199924.pdf
Cambridge-Practice-Tests-for-IELTS-12.docx
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Hazard Identification & Risk Assessment .pdf
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
Introduction to pro and eukaryotes and differences.pptx
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
20th Century Theater, Methods, History.pptx
TNA_Presentation-1-Final(SAVE)) (1).pptx
History, Philosophy and sociology of education (1).pptx
Weekly quiz Compilation Jan -July 25.pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
Practical Manual AGRO-233 Principles and Practices of Natural Farming
What if we spent less time fighting change, and more time building what’s rig...
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
International_Financial_Reporting_Standa.pdf
Chinmaya Tiranga Azadi Quiz (Class 7-8 )

Huffman Tree And Its Application

  • 1. PRESENTED TO:- DR. M.C.LOHANI BY:- PAPU KUMAR SECTION:- B ROLL NO.:- 2061424(47) SEMESTER:- III BRANCH:- C.S.E. HUffMAN TREE & IT’S APPLICATION
  • 2. Encoding and Compression of Data • Fax Machines • ASCII • Variations on ASCII • min number of bits needed • cost of savings • patterns • modifications
  • 3. Application • 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
  • 4. 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
  • 5. 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 eor x
  • 6. 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.
  • 7. 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.
  • 8. 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
  • 9. 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 .
  • 10. 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
  • 11. 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
  • 12. 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. 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
  • 15. 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. 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. Building a Tree E i k 1 . 1 r 2 s 2 n 2 a 2 sp 4 e 8 y l
  • 18. 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. Building a Tree E i r 2 s 2 n 2 a 2 sp 4 e 8 2 y l 2 k . 2
  • 20. Building a Tree E i r 2 s 2 n 2 a 2 sp 4 e 8 2 y l 2 k . 2
  • 21. Building a Tree E i n 2 a 2 sp 4 e 8 2 y l 2 k . 2 r s 4
  • 22. Building a Tree E i n 2 a 2 sp 4 e 8 2 y l 2 k . 2 r s 4
  • 23. Building a Tree E i sp 4 e 8 2 y l 2 k . 2 r s 4 n a 4
  • 24. Building a Tree E i sp 4 e 8 2 y l 2 k . 2 r s 4 n a 4
  • 25. Building a Tree E i sp 4 e 8 2 y l 2 k . 2 r s 4 n a 4 4
  • 26. Building a Tree E i sp 4 e 82 y l 2 k . 2 r s 4 n a 4 4
  • 27. Building a Tree E i sp e 82 y l 2 k . 2 r s 4 n a 4 4 6
  • 28. 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. Building a Tree E i sp e 82 y l 2 k . 2 r s 4 n a 4 4 6 8
  • 30. Building a Tree E i sp e 82 y l 2 k . 2 r s 4 n a 4 4 6 8
  • 31. 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. Building a Tree E i sp e 8 2 y l 2 k . 2r s 4 n a 4 4 6 8 10
  • 33. Building a Tree E i sp e2 y l 2 k . 2 r s 4 n a 4 4 6 8 10 16
  • 34. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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