Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more ➡
Standard view
Full view
of .
×
0 of .
Results for:
P. 1
Huff Man 1

# Huff Man 1

Ratings: 0|Views: 49|Likes:

### Availability:

See More
See less

10/19/2011

pdf

text

original

1
Q -1
File Compression and Huffman Codes
CLRS Reading:Section 16.3, pages 428 --437Problem Set:Assignment #8 due Thursday, April 14
Q -2
Binary Code
Q -3
Improving on ASCII
ASCII uses eight bits in order to store 2
8
distinctcharacters. If our file uses fewer characters, wemight do better with a different code.For example, rather than store “ABRACADABRA”ineight bit ASCII code, we store it in our own personalfive bit binary code (A = 00001, B = 00010, …)*.
0000100010100100000100011000010010000001000101001000001
*This represents a 37.5% savings over the ASCII encoding. But wecan do better if we give up thenotion of fixed encoding length.
Q -4
Variable-Length Encoding
Assign shortest bit strings to the most commonlyused letters: A=0, B=1, R=01, C=10, D=11. SoABRACADADBRA becomes
0 1 01 0 10 0 11 0 1 01 0
This uses only 15 bits compared to 55 in ourprevious scheme. But it does require blanks toseparate the characters.

2
Q -5
Epiphany
Without the spaces, the encoding ofABRACADABRA is ambiguous:
010101001101010
For example, is the first bit an A or the start ofthe pair 01 representing an R*?But, delimiters aren’t needed if no character codeis the prefix of another.
*Recall, A=0, B=1, R=01, C=10, D=11.
Q -6
Prefix Codes
An improved code for the message ABRACADABRAis given by
A11B00C010D10R011
The message ABRACADABRA is translated as the25-bit string:
1100011110101110110001111
Q -7
Coding Trees
Decoding needs a convenient representation for theprefix code.For example, 1100011110101110110001111.
*Recall, A=11, B=00, R=011, C=010, D=10.
Q -8
Cost of Tree
Definition
Let
be the code tree corresponding to aprefix code. Define
(
) =
Σ
c.freq
*
(
)where
c.freq
is the frequency of character
and
(
) denotes
’s depth in
.
*What is the cost of the ABRACADABRA tree given in the previous slide?

3
Q -9
Can We Do Better?
ABRACADABRA tree yielding 23 bit string
01101001111011100110100
.
ARBDC
Q -10
Huffman Codes
Huffman encoding
is a method for constructing atree which leads to a bit string of minimal length forany given message.The first step is to find the frequency counts forthe message. For example,ABRACADABRAFrequency Table
A5B2C1D1R2
Q -11
Build Tree Bottom Up
Maintain a priority queue
keyed on frequency.Remove the two trees with smallest root values andmerge them into a new tree.
C:1D:1B:2R:2A:5
Q -12
Repeat
C:1D:1B:2R:2A:52

## Activity (0)

### Showing

AllMost RecentReviewsAll NotesLikes