Huffman Coding - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

Huffman Coding

Description:

IKI 10100: Data Structures & Algorithms. Ruli Manurung (acknowledgments to Denny & Ade Azurat) ... RLE: Run Length Encoding. Lempel-Ziv. Huffman Encoding ... – PowerPoint PPT presentation

Number of Views:210
Avg rating:3.0/5.0
Slides: 26
Provided by: dn5
Category:
Tags: coding | huffman | run | up

less

Transcript and Presenter's Notes

Title: Huffman Coding


1
Huffman Coding
2
Outline
  • Data Compression
  • Huffman Coding

3
Compression
  • Process
  • Encoding raw ? compressed
  • Decoding compressed ? raw
  • Types of compression
  • Lossy MP3, JPG
  • Lossless ZIP, GZ
  • Compression Algorithm
  • RLE Run Length Encoding
  • Lempel-Ziv
  • Huffman Encoding
  • Performance of compression depends on file types.

4
Huffman Compression
  • If a woodchuck could chuck wood!
  • 32 char ? 8 bit 256 bits
  • 13 distinct characters ? 4 bit
  • Compressed code 128 bits
  • Variable length string of bits to further improve
    compression.
  • Using prefix codes
  • Main idea
  • Frequently occurring letters short
    representation.
  • Infrequent letters long representations.

5
Huffman Encoding Comparison
a 00 ? 16 bits i 01 ? 10 bits u 10 ? 6
bits e 11 ? 6 bits Total 42 bits
8
5
3
3
6
Huffman Encoding Comparison
a 0 ? 8 bits i 10 ? 10 bits u 110 ? 9
bits e 111 ? 9 bits Total 36 bits
7
Huffman Encoding
d
c
space
o
u
k
w
h
!
I
f
a
l
8
Huffman Encoding
32
19
13
9
7
10
6
4
4
o5
d3
c5
3
space5
2
u3
k2
w2
2
h2
!1
I1
f1
a1
l1
9
Huffman Encoding (freq)
  • ! 0000 (1) I 10000 (1)
  • a 00010 (1) f 10001 (1)
  • l 00011 (1) h 1001 (2)
  • u 001 (3) c 101 (5)
  • d 010 (3) space 110 (5)
  • k 0110 (2) o 111 (5)
  • w 0111 (2)
  • Cost ? di fi 111 bits 44 ? 256 bits

10
Huffman Encoding steps
2
11
Huffman Encoding steps
12
Huffman Encoding steps
13
Huffman Encoding steps
14
Huffman Encoding steps
15
Huffman Encoding steps
16
Huffman Encoding steps
6
4
4
k
17
Huffman Encoding steps
6
7
4
4
k
18
Huffman Encoding steps
19
Huffman Encoding steps
20
Huffman Encoding steps
21
Huffman Encoding steps
22
Huffman Encoding steps
13
23
Huffman Encoding steps
Total 111 bits
24
How do we implement this?
  • Use a priority queue!
  • Maintain a forest of trees
  • Each element in the queue is a root node
  • Order them by character frequency count
  • Algorithm
  • Add all unique characters as single node tree
  • Call dequeue twice, merge trees, enqueue result
  • Repeat until only 1 tree left!

25
Summary
  • Huffman encoding uses character frequency
    information to compress a file.
  • The most frequent character gets a shorter prefix
    code, and vice versa.
Write a Comment
User Comments (0)
About PowerShow.com