SlideShare a Scribd company logo
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
Lexical analysis - Compiler Design
Muhammed Afsal Villan
 
PPTX
Context free grammar
Mohammad Ilyas Malik
 
PPTX
Type checking in compiler design
Sudip Singh
 
PDF
Code optimization in compiler design
Kuppusamy P
 
PPTX
Three address code In Compiler Design
Shine Raj
 
PPTX
Phases of Compiler
Tanzeela_Hussain
 
PDF
Lexical Analysis - Compiler design
Aman Sharma
 
PPTX
Compiler Design Unit 4
Jena Catherine Bel D
 
Lexical analysis - Compiler Design
Muhammed Afsal Villan
 
Context free grammar
Mohammad Ilyas Malik
 
Type checking in compiler design
Sudip Singh
 
Code optimization in compiler design
Kuppusamy P
 
Three address code In Compiler Design
Shine Raj
 
Phases of Compiler
Tanzeela_Hussain
 
Lexical Analysis - Compiler design
Aman Sharma
 
Compiler Design Unit 4
Jena Catherine Bel D
 

What's hot (20)

PPTX
Code generation
Aparna Nayak
 
PPTX
Semantics analysis
Bilalzafar22
 
PPTX
8 queens problem using back tracking
Tech_MX
 
PPT
Ll(1) Parser in Compilers
Mahbubur Rahman
 
PPTX
Compilers
Bense Tony
 
PPT
Algorithm analysis
sumitbardhan
 
PPTX
Data structure tries
Md. Naim khan
 
PPTX
Lecture optimal binary search tree
Divya Ks
 
PDF
Memory management
Rajni Sirohi
 
PPT
EULER AND FERMAT THEOREM
ankita pandey
 
PPTX
Lecture 10 semantic analysis 01
Iffat Anjum
 
PPTX
Cs419 lec10 left recursion and left factoring
Arab Open University and Cairo University
 
PPTX
Basic blocks and control flow graphs
Tilakpoudel2
 
PPTX
Universal turing coastus
Shiraz316
 
PPTX
Passes of Compiler.pptx
Sanjay Singh
 
PPTX
MACRO PROCESSOR
Bhavik Vashi
 
PPTX
Role-of-lexical-analysis
Dattatray Gandhmal
 
PPT
Intermediate code generation (Compiler Design)
Tasif Tanzim
 
PPT
Type Checking(Compiler Design) #ShareThisIfYouLike
United International University
 
PPTX
Algorithm and pseudocode conventions
saranyatdr
 
Code generation
Aparna Nayak
 
Semantics analysis
Bilalzafar22
 
8 queens problem using back tracking
Tech_MX
 
Ll(1) Parser in Compilers
Mahbubur Rahman
 
Compilers
Bense Tony
 
Algorithm analysis
sumitbardhan
 
Data structure tries
Md. Naim khan
 
Lecture optimal binary search tree
Divya Ks
 
Memory management
Rajni Sirohi
 
EULER AND FERMAT THEOREM
ankita pandey
 
Lecture 10 semantic analysis 01
Iffat Anjum
 
Cs419 lec10 left recursion and left factoring
Arab Open University and Cairo University
 
Basic blocks and control flow graphs
Tilakpoudel2
 
Universal turing coastus
Shiraz316
 
Passes of Compiler.pptx
Sanjay Singh
 
MACRO PROCESSOR
Bhavik Vashi
 
Role-of-lexical-analysis
Dattatray Gandhmal
 
Intermediate code generation (Compiler Design)
Tasif Tanzim
 
Type Checking(Compiler Design) #ShareThisIfYouLike
United International University
 
Algorithm and pseudocode conventions
saranyatdr
 
Ad

Viewers also liked (19)

PPTX
Huffman Coding
Ehtisham Ali
 
PPTX
Greedy Algorithm
Neil Lee
 
PDF
Huffman Encoding Pr
anithabalaprabhu
 
PPTX
Huffman tree
Al-amin Hossain
 
PPTX
Huffman coding
Bagus Nugroho
 
PDF
3G Transport Profile
Greengrass Generaltransport
 
PDF
File compression sunzip (huffman algorithm)
mini_61
 
PPT
Hufman coding basic
radthees
 
PPTX
investigación cientifica
1005877079
 
PPTX
The new Wilson VH3300 Automated Knoop/Vickers Hardness Tester
Simone Hebel
 
PDF
An Essential Relationship between Real-time and Resource Partitioning
Yoshitake Kobayashi
 
PPT
Chapter%202%20 %20 Text%20compression(2)
nes
 
PPTX
Cours4.1 recherche documentaire-outils
Evelyne Brémond
 
PPTX
Cours4.4 google
Evelyne Brémond
 
PPTX
Computer architecture
International Islamic University
 
PPT
0 introduction to computer architecture
aamc1100
 
PPT
Huffman Coding
anithabalaprabhu
 
PPTX
Memory Organization
Dilum Bandara
 
PPT
Computer architecture
Sanjeev Patel
 
Huffman Coding
Ehtisham Ali
 
Greedy Algorithm
Neil Lee
 
Huffman Encoding Pr
anithabalaprabhu
 
Huffman tree
Al-amin Hossain
 
Huffman coding
Bagus Nugroho
 
3G Transport Profile
Greengrass Generaltransport
 
File compression sunzip (huffman algorithm)
mini_61
 
Hufman coding basic
radthees
 
investigación cientifica
1005877079
 
The new Wilson VH3300 Automated Knoop/Vickers Hardness Tester
Simone Hebel
 
An Essential Relationship between Real-time and Resource Partitioning
Yoshitake Kobayashi
 
Chapter%202%20 %20 Text%20compression(2)
nes
 
Cours4.1 recherche documentaire-outils
Evelyne Brémond
 
Cours4.4 google
Evelyne Brémond
 
Computer architecture
International Islamic University
 
0 introduction to computer architecture
aamc1100
 
Huffman Coding
anithabalaprabhu
 
Memory Organization
Dilum Bandara
 
Computer architecture
Sanjeev Patel
 
Ad

Similar to Huffman Tree And Its Application (20)

PPT
Huffman > Data Structures & Algorithums
Ain-ul-Moiz Khawaja
 
PPT
Data Structure and Algorithms Huffman Coding Algorithm
ManishPrajapati78
 
PDF
CS-102 Data Structures huffman coding.pdf
ssuser034ce1
 
PPTX
Huffman.pptx
HarisMasood20
 
PPT
Huffman 2
grupo6tic
 
PPT
Huffman1
anithabalaprabhu
 
PPT
Huffman
anithabalaprabhu
 
PPTX
Data compession
arvind carpenter
 
PPT
Greedy Algorithms Huffman Coding.ppt
Ruchika Sinha
 
PPT
huffman codes and algorithm
Vinay379568
 
PPT
huffman_nyu.ppt ghgghtttjghh hhhhhhhhhhh
BARUNSINGH43
 
PPT
huffman algoritm upload for understand.ppt
SadiaSharmin40
 
PPT
Huffman
Priyanka Chauhan
 
PPTX
Huffman Codes
Md. Shafiuzzaman Hira
 
PPT
computer notes - Data Structures - 23
ecomputernotes
 
PPTX
Data structures' project
Behappy Seehappy
 
PPT
computer notes - Data Structures - 24
ecomputernotes
 
PPT
trees.ppt
jawraabdul
 
PPT
Computer notes - Expression Tree
ecomputernotes
 
DOC
HuffmanCoding01.doc
Qwertty3
 
Huffman > Data Structures & Algorithums
Ain-ul-Moiz Khawaja
 
Data Structure and Algorithms Huffman Coding Algorithm
ManishPrajapati78
 
CS-102 Data Structures huffman coding.pdf
ssuser034ce1
 
Huffman.pptx
HarisMasood20
 
Huffman 2
grupo6tic
 
Data compession
arvind carpenter
 
Greedy Algorithms Huffman Coding.ppt
Ruchika Sinha
 
huffman codes and algorithm
Vinay379568
 
huffman_nyu.ppt ghgghtttjghh hhhhhhhhhhh
BARUNSINGH43
 
huffman algoritm upload for understand.ppt
SadiaSharmin40
 
Huffman Codes
Md. Shafiuzzaman Hira
 
computer notes - Data Structures - 23
ecomputernotes
 
Data structures' project
Behappy Seehappy
 
computer notes - Data Structures - 24
ecomputernotes
 
trees.ppt
jawraabdul
 
Computer notes - Expression Tree
ecomputernotes
 
HuffmanCoding01.doc
Qwertty3
 

Recently uploaded (20)

PPTX
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
PDF
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PPTX
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
PPTX
BASICS IN COMPUTER APPLICATIONS - UNIT I
suganthim28
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PPTX
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
PDF
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PPTX
Gupta Art & Architecture Temple and Sculptures.pptx
Virag Sontakke
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
PPTX
A Smarter Way to Think About Choosing a College
Cyndy McDonald
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PPTX
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
BASICS IN COMPUTER APPLICATIONS - UNIT I
suganthim28
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
Gupta Art & Architecture Temple and Sculptures.pptx
Virag Sontakke
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
A Smarter Way to Think About Choosing a College
Cyndy McDonald
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 

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