Assignment 6: Huffman Code Generation - PowerPoint PPT Presentation

About This Presentation
Title:

Assignment 6: Huffman Code Generation

Description:

... proportional to the frequency of its occurrences. ASCII Encoding ... ASCII ... Printing out the code table. Frequency Analysis. TALLAHASSEE. A 3. E 2 ... – PowerPoint PPT presentation

Number of Views:157
Avg rating:3.0/5.0
Slides: 33
Provided by: csF2
Learn more at: http://www.cs.fsu.edu
Category:

less

Transcript and Presenter's Notes

Title: Assignment 6: Huffman Code Generation


1
Assignment 6 Huffman Code Generation
  • Andy Wang
  • Data Structures, Algorithms, and Generic
    Programming

2
Huffman Code
  • Commonly used in compression schemes
  • Idea
  • Use variable-length code words
  • Length of the word inversely proportional to the
    frequency of its occurrences

3
ASCII Encoding
  • TALLAHASSEE
  • ASCII values
  • A 0100 0001
  • E 0100 0101
  • H 0100 1000
  • L 0100 1100
  • S 0101 0011
  • T 0101 0100

4
ASCII Encoding
  • TALLAHASSEE
  • 0101 0100 0100 0001 0100 1100 0100 1100 0100 0001
    0100 1000 0100 0001 0101 0011 0101 0011 0100 0101
    0100 0101
  • 811 88 bits

5
Huffman Encoding
  • TALLAHASSEE
  • A 10
  • E 00
  • H 010
  • L 110
  • S 111
  • T 011

6
Huffman Encoding
  • TALLAHASSEE
  • 011 10 110 110 10 010 10 111 111 00 00
  • 28 bits

7
Assignment 6
  • Generate Huffman Code
  • Frequency analysis
  • Constructing the code tree
  • Printing out the code table

8
Frequency Analysis
  • TALLAHASSEE
  • A 3
  • E 2
  • H 1
  • L 2
  • S 2
  • T 1

9
Constructing the Code Tree
  • Create tree nodes

E2
A3
H1
L2
T1
S2
10
Constructing the Code Tree
  • Build a modified heap

A3
L2
H1
T1
S2
E2
11
Constructing the Code Tree
  • Find two nodes with the smallest counter values

A3
L2
T1
S2
E2
H1
12
Constructing the Code Tree
  • Find two nodes with the smallest counter values

A3
L2
S2
E2
H1
T1
13
Constructing the Code Tree
  • Create a parent node

A3
L2
S2
E2
14
Constructing the Code Tree
  • Insert the parent node back to the heap

A3
L2
S2
E2
15
Constructing the Code Tree
  • Find two nodes with the smallest counter values

A3
L2
S2
E2
16
Constructing the Code Tree
  • Find two nodes with the smallest counter values

A3
L2
S2
E2
17
Constructing the Code Tree
  • Create a parent node

A3
L2
S2
18
Constructing the Code Tree
  • Insert the parent node back to the heap

A3
L2
S2
19
Constructing the Code Tree
  • Find two nodes with the smallest counter values

A3
S2
L2
20
Constructing the Code Tree
  • Find two nodes with the smallest counter values

A3
L2
S2
21
Constructing the Code Tree
  • Create a parent node

A3
4
E2
2
4
T1
L2
S2
H1
22
Constructing the Code Tree
  • Insert the parent node back to the heap

A3
4
E2
2
T1
H1
23
Constructing the Code Tree
  • Find two nodes with the smallest counter values

4
A3
E2
2
T1
H1
24
Constructing the Code Tree
  • Find two nodes with the smallest counter values

A3
25
Constructing the Code Tree
  • Create a parent node

7
4
A3
E2
2
T1
H1
26
Constructing the Code Tree
  • Insert the parent node back to the heap

27
Constructing the Code Tree
  • Find two nodes with the smallest counter values

28
Constructing the Code Tree
  • Find two nodes with the smallest counter values

4
E2
2
T1
H1
29
Constructing the Code Tree
  • Create a parent node

11
4
E2
2
T1
H1
30
Constructing the Code Tree
  • Insert the parent node back to the heap

11
4
E2
2
T1
H1
31
Code Assignment
11
1
0
4
1
0
0
1
E2
2
0
1
1
00
0
10
T1
H1
010
011
110
111
32
Properties of Huffman Code
  • Higher the frequency, shorter the code
  • The code for one character is not the prefix for
    another code
  • 00 is not a prefix for 010
  • 00 is a prefix for 001
Write a Comment
User Comments (0)
About PowerShow.com