SlideShare a Scribd company logo
1 of 29
Compression & Huffman Codes
Compression
Definition
Reduce size of data
(number of bits needed to represent data)
Benefits
Reduce storage needed
Reduce transmission cost / latency / bandwidth
Sources of Compressibility
Redundancy
Recognize repeating patterns
Exploit using
Dictionary
Variable length encoding
Human perception
Less sensitive to some information
Can discard less important data
Types of Compression
Lossless
Preserves all information
Exploits redundancy in data
Applied to general data
Lossy
May lose some information
Exploits redundancy & human perception
Applied to audio, image, video
Effectiveness of Compression
Metrics
Bits per byte (8 bits)
2 bits / byte  ¼ original size
8 bits / byte  no compression
Percentage
75% compression  ¼ original size
Effectiveness of Compression
Depends on data
Random data  hard
Example: 1001110100  ?
Organized data  easy
Example: 1111111111  110
Corollary
No universally best compression algorithm
Effectiveness of Compression
Lossless Compression is not always possible
If compression is always possible (alternative view)
Compress file (reduce size by 1 bit)
Recompress output
Repeat (until we can store data with 0 bits)
Lossless Compression Techniques
LZW (Lempel-Ziv-Welch) compression
Build pattern dictionary
Replace patterns with index into dictionary
Run length encoding
Find & compress repetitive sequences
Huffman codes
Use variable length codes based on frequency
Huffman Code
Approach
Variable length encoding of symbols
Exploit statistical frequency of symbols
Efficient when symbol probabilities vary widely
Principle
Use fewer bits to represent frequent symbols
Use more bits to represent infrequent symbols
A A B A
A A
A B
Huffman Code Example
Expected size
Original  1/82 + 1/42 + 1/22 + 1/82 = 2 bits / symbol
Huffman  1/83 + 1/42 + 1/21 + 1/83 = 1.75 bits / symbol
Symbol A B C D
Frequency 13% 25% 50% 12%
Original
Encoding
00 01 10 11
2 bits 2 bits 2 bits 2 bits
Huffman
Encoding
110 10 0 111
3 bits 2 bits 1 bit 3 bits
Huffman Code Data Structures
Binary (Huffman) tree
Represents Huffman code
Edge  code (0 or 1)
Leaf  symbol
Path to leaf  encoding
Example
A = “110”, B = “10”, C = “0”
Priority queue
To efficiently build binary tree 1
1 0
0
D
C
B
A
0
1
Huffman Code Algorithm Overview
Encoding
Calculate frequency of symbols in file
Create binary tree representing “best” encoding
Use binary tree to encode compressed file
For each symbol, output path from root to leaf
Size of encoding = length of path
Save binary tree
Huffman Code – Creating Tree
Algorithm
Place each symbol in leaf
Weight of leaf = symbol frequency
Select two trees L and R (initially leafs)
Such that L, R have lowest frequencies in tree
Create new (internal) node
Left child  L
Right child  R
New frequency  frequency( L ) + frequency( R )
Repeat until all nodes merged into one tree
Huffman Tree Construction 1
3 5 8 2 7
A C E H I
Huffman Tree Construction 2
3 5 8
2 7
5
A C E
H I
Huffman Tree Construction 3
3
5
8
2
7
5
10
A
C
E
H
I
Huffman Tree Construction 4
3
5
8
2
7
5
10
15
A
C
E
H
I
Huffman Tree Construction 5
3
5 8
2
7
5
10 15
25
1
1
1
1
0
0
0
0
A
C E
H
I
E = 01
I = 00
C = 10
A = 111
H = 110
Huffman Coding Example
Huffman code
Input
ACE
Output
(111)(10)(01) = 1111001
E = 01
I = 00
C = 10
A = 111
H = 110
Huffman Code Algorithm Overview
Decoding
Read compressed file & binary tree
Use binary tree to decode file
Follow path from root to leaf
Huffman Decoding 1
3
5 8
2
7
5
10 15
25
1
1
1
1
0
0
0
0
A
C E
H
I
1111001
Huffman Decoding 2
3
5 8
2
7
5
10 15
25
1
1
1
1
0
0
0
0
A
C E
H
I
1111001
Huffman Decoding 3
3
5 8
2
7
5
10 15
25
1
1
1
1
0
0
0
0
A
C E
H
I
1111001
A
Huffman Decoding 4
3
5 8
2
7
5
10 15
25
1
1
1
1
0
0
0
0
A
C E
H
I
1111001
A
Huffman Decoding 5
3
5 8
2
7
5
10 15
25
1
1
1
1
0
0
0
0
A
C E
H
I
1111001
AC
Huffman Decoding 6
3
5 8
2
7
5
10 15
25
1
1
1
1
0
0
0
0
A
C E
H
I
1111001
AC
Huffman Decoding 7
3
5 8
2
7
5
10 15
25
1
1
1
1
0
0
0
0
A
C E
H
I
1111001
ACE
Huffman Code Properties
Prefix code
No code is a prefix of another code
Example
Huffman(“I”)  00
Huffman(“X”)  001 // not legal prefix code
Can stop as soon as complete code found
No need for end-of-code marker
Nondeterministic
Multiple Huffman coding possible for same input
If more than two trees with same minimal weight
Huffman Code Properties
Greedy algorithm
Chooses best local solution at each step
Combines 2 trees with lowest frequency
Still yields overall best solution
Optimal prefix code
Based on statistical frequency
Better compression possible (depends on data)
Using other approaches (e.g., pattern dictionary)

More Related Content

Similar to hufman code presentation and how to compress data using hufman code

2.3 unit-ii-text-compression-a-outline-compression-techniques-run-length-codi...
2.3 unit-ii-text-compression-a-outline-compression-techniques-run-length-codi...2.3 unit-ii-text-compression-a-outline-compression-techniques-run-length-codi...
2.3 unit-ii-text-compression-a-outline-compression-techniques-run-length-codi...Helan4
 
Chapter%202%20 %20 Text%20compression(2)
Chapter%202%20 %20 Text%20compression(2)Chapter%202%20 %20 Text%20compression(2)
Chapter%202%20 %20 Text%20compression(2)nes
 
Chapter 4 Lossless Compression Algorithims.pptx
Chapter 4 Lossless Compression Algorithims.pptxChapter 4 Lossless Compression Algorithims.pptx
Chapter 4 Lossless Compression Algorithims.pptxMedinaBedru
 
Hufman coding basic
Hufman coding basicHufman coding basic
Hufman coding basicradthees
 
Farhana shaikh webinar_huffman coding
Farhana shaikh webinar_huffman codingFarhana shaikh webinar_huffman coding
Farhana shaikh webinar_huffman codingFarhana Shaikh
 
Sunzip user tool for data reduction using huffman algorithm
Sunzip user tool for data reduction using huffman algorithmSunzip user tool for data reduction using huffman algorithm
Sunzip user tool for data reduction using huffman algorithmDr Sandeep Kumar Poonia
 
Data representation
Data representationData representation
Data representationChingTing
 
Noise infotheory1
Noise infotheory1Noise infotheory1
Noise infotheory1vmspraneeth
 
Noise info theory and Entrophy
Noise info theory and EntrophyNoise info theory and Entrophy
Noise info theory and EntrophyIzah Asmadi
 
Computer Concepts
Computer ConceptsComputer Concepts
Computer ConceptsPhoebe Kim
 
Module-IV 094.pdf
Module-IV 094.pdfModule-IV 094.pdf
Module-IV 094.pdfSamrajECE
 
Ig2 task 1 work sheet (glossary) steph hawkins
Ig2 task 1 work sheet (glossary) steph hawkinsIg2 task 1 work sheet (glossary) steph hawkins
Ig2 task 1 work sheet (glossary) steph hawkinsstephlizahawkins123
 

Similar to hufman code presentation and how to compress data using hufman code (20)

2.3 unit-ii-text-compression-a-outline-compression-techniques-run-length-codi...
2.3 unit-ii-text-compression-a-outline-compression-techniques-run-length-codi...2.3 unit-ii-text-compression-a-outline-compression-techniques-run-length-codi...
2.3 unit-ii-text-compression-a-outline-compression-techniques-run-length-codi...
 
Arithmetic Coding
Arithmetic CodingArithmetic Coding
Arithmetic Coding
 
Chapter%202%20 %20 Text%20compression(2)
Chapter%202%20 %20 Text%20compression(2)Chapter%202%20 %20 Text%20compression(2)
Chapter%202%20 %20 Text%20compression(2)
 
Chapter 4 Lossless Compression Algorithims.pptx
Chapter 4 Lossless Compression Algorithims.pptxChapter 4 Lossless Compression Algorithims.pptx
Chapter 4 Lossless Compression Algorithims.pptx
 
Data Compression
Data CompressionData Compression
Data Compression
 
Hufman coding basic
Hufman coding basicHufman coding basic
Hufman coding basic
 
Farhana shaikh webinar_huffman coding
Farhana shaikh webinar_huffman codingFarhana shaikh webinar_huffman coding
Farhana shaikh webinar_huffman coding
 
Speaker Segmentation (2006)
Speaker Segmentation (2006)Speaker Segmentation (2006)
Speaker Segmentation (2006)
 
Data compression
Data compressionData compression
Data compression
 
Sunzip user tool for data reduction using huffman algorithm
Sunzip user tool for data reduction using huffman algorithmSunzip user tool for data reduction using huffman algorithm
Sunzip user tool for data reduction using huffman algorithm
 
Image compression
Image compressionImage compression
Image compression
 
Introduction Data Compression/ Data compression, modelling and coding,Image C...
Introduction Data Compression/ Data compression, modelling and coding,Image C...Introduction Data Compression/ Data compression, modelling and coding,Image C...
Introduction Data Compression/ Data compression, modelling and coding,Image C...
 
Data representation
Data representationData representation
Data representation
 
Noise infotheory1
Noise infotheory1Noise infotheory1
Noise infotheory1
 
Noise info theory and Entrophy
Noise info theory and EntrophyNoise info theory and Entrophy
Noise info theory and Entrophy
 
Computer Concepts
Computer ConceptsComputer Concepts
Computer Concepts
 
Data representation
Data representationData representation
Data representation
 
Data representation
Data representationData representation
Data representation
 
Module-IV 094.pdf
Module-IV 094.pdfModule-IV 094.pdf
Module-IV 094.pdf
 
Ig2 task 1 work sheet (glossary) steph hawkins
Ig2 task 1 work sheet (glossary) steph hawkinsIg2 task 1 work sheet (glossary) steph hawkins
Ig2 task 1 work sheet (glossary) steph hawkins
 

Recently uploaded

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 

Recently uploaded (20)

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 

hufman code presentation and how to compress data using hufman code

  • 2. Compression Definition Reduce size of data (number of bits needed to represent data) Benefits Reduce storage needed Reduce transmission cost / latency / bandwidth
  • 3. Sources of Compressibility Redundancy Recognize repeating patterns Exploit using Dictionary Variable length encoding Human perception Less sensitive to some information Can discard less important data
  • 4. Types of Compression Lossless Preserves all information Exploits redundancy in data Applied to general data Lossy May lose some information Exploits redundancy & human perception Applied to audio, image, video
  • 5. Effectiveness of Compression Metrics Bits per byte (8 bits) 2 bits / byte  ¼ original size 8 bits / byte  no compression Percentage 75% compression  ¼ original size
  • 6. Effectiveness of Compression Depends on data Random data  hard Example: 1001110100  ? Organized data  easy Example: 1111111111  110 Corollary No universally best compression algorithm
  • 7. Effectiveness of Compression Lossless Compression is not always possible If compression is always possible (alternative view) Compress file (reduce size by 1 bit) Recompress output Repeat (until we can store data with 0 bits)
  • 8. Lossless Compression Techniques LZW (Lempel-Ziv-Welch) compression Build pattern dictionary Replace patterns with index into dictionary Run length encoding Find & compress repetitive sequences Huffman codes Use variable length codes based on frequency
  • 9. Huffman Code Approach Variable length encoding of symbols Exploit statistical frequency of symbols Efficient when symbol probabilities vary widely Principle Use fewer bits to represent frequent symbols Use more bits to represent infrequent symbols A A B A A A A B
  • 10. Huffman Code Example Expected size Original  1/82 + 1/42 + 1/22 + 1/82 = 2 bits / symbol Huffman  1/83 + 1/42 + 1/21 + 1/83 = 1.75 bits / symbol Symbol A B C D Frequency 13% 25% 50% 12% Original Encoding 00 01 10 11 2 bits 2 bits 2 bits 2 bits Huffman Encoding 110 10 0 111 3 bits 2 bits 1 bit 3 bits
  • 11. Huffman Code Data Structures Binary (Huffman) tree Represents Huffman code Edge  code (0 or 1) Leaf  symbol Path to leaf  encoding Example A = “110”, B = “10”, C = “0” Priority queue To efficiently build binary tree 1 1 0 0 D C B A 0 1
  • 12. Huffman Code Algorithm Overview Encoding Calculate frequency of symbols in file Create binary tree representing “best” encoding Use binary tree to encode compressed file For each symbol, output path from root to leaf Size of encoding = length of path Save binary tree
  • 13. Huffman Code – Creating Tree Algorithm Place each symbol in leaf Weight of leaf = symbol frequency Select two trees L and R (initially leafs) Such that L, R have lowest frequencies in tree Create new (internal) node Left child  L Right child  R New frequency  frequency( L ) + frequency( R ) Repeat until all nodes merged into one tree
  • 14. Huffman Tree Construction 1 3 5 8 2 7 A C E H I
  • 15. Huffman Tree Construction 2 3 5 8 2 7 5 A C E H I
  • 16. Huffman Tree Construction 3 3 5 8 2 7 5 10 A C E H I
  • 17. Huffman Tree Construction 4 3 5 8 2 7 5 10 15 A C E H I
  • 18. Huffman Tree Construction 5 3 5 8 2 7 5 10 15 25 1 1 1 1 0 0 0 0 A C E H I E = 01 I = 00 C = 10 A = 111 H = 110
  • 19. Huffman Coding Example Huffman code Input ACE Output (111)(10)(01) = 1111001 E = 01 I = 00 C = 10 A = 111 H = 110
  • 20. Huffman Code Algorithm Overview Decoding Read compressed file & binary tree Use binary tree to decode file Follow path from root to leaf
  • 21. Huffman Decoding 1 3 5 8 2 7 5 10 15 25 1 1 1 1 0 0 0 0 A C E H I 1111001
  • 22. Huffman Decoding 2 3 5 8 2 7 5 10 15 25 1 1 1 1 0 0 0 0 A C E H I 1111001
  • 23. Huffman Decoding 3 3 5 8 2 7 5 10 15 25 1 1 1 1 0 0 0 0 A C E H I 1111001 A
  • 24. Huffman Decoding 4 3 5 8 2 7 5 10 15 25 1 1 1 1 0 0 0 0 A C E H I 1111001 A
  • 25. Huffman Decoding 5 3 5 8 2 7 5 10 15 25 1 1 1 1 0 0 0 0 A C E H I 1111001 AC
  • 26. Huffman Decoding 6 3 5 8 2 7 5 10 15 25 1 1 1 1 0 0 0 0 A C E H I 1111001 AC
  • 27. Huffman Decoding 7 3 5 8 2 7 5 10 15 25 1 1 1 1 0 0 0 0 A C E H I 1111001 ACE
  • 28. Huffman Code Properties Prefix code No code is a prefix of another code Example Huffman(“I”)  00 Huffman(“X”)  001 // not legal prefix code Can stop as soon as complete code found No need for end-of-code marker Nondeterministic Multiple Huffman coding possible for same input If more than two trees with same minimal weight
  • 29. Huffman Code Properties Greedy algorithm Chooses best local solution at each step Combines 2 trees with lowest frequency Still yields overall best solution Optimal prefix code Based on statistical frequency Better compression possible (depends on data) Using other approaches (e.g., pattern dictionary)