





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






0000100010100100000100011000010010000001000101001000001
*This represents a 37.5% savings over the ASCII encoding. But we can do better if we give up the notion of fixed encoding length.
0 1 01 0 10 0 11 0 1 01 0
For example, is the first bit an A or the start of the pair 01 representing an R*.
*Recall A=0, B=1, R=01, C=10, D=11.
Definition Let T be the code tree corresponding to a prefix code. Define
where f(c) is the frequency of character c and d (^) T (c) denotes c 's depth in T.
*What is the cost of the ABRACADABRA tree given in the previous slide.
A R
C
B D
ABRACADABRA Frequency Table A 5 B 2 C 1 D 1 R 2
Huffman (C) n โ |C| Q โ C for i โ 1 to n- do z โ Allocate-Node() x โ left [ z ] โ Extract-Min( Q ) y โ right [ z ] โ Extract-Min( Q ) f[z] โ f[x] + f[y] Insert( Q,z ) return Extract-Min( Q )
Let x, y โ C have minimum frequencies.
Then there exists an optimal prefix code for C in which the codewords for x,y have the same length and differ only in the last bit.
b
a
x y
T''
y
x
a b
T
y
a
x b
T'
b
a
x y
T''
Choose a and b be sibling leaves at maximum depth in T.
Since x is min frequency f[x] โค f[a] and cost[ T' ] โค cost[ T ].
Let x, y โ C have minimum frequencies, and T be any optimal prefix code tree for C in which x, y are siblings_._
Tree T ' obtained from T by replacing the parent of leaves x, y by leaf z, with f[z] = f[x] + f[y], is an optimal prefix code tree for C' = C - {x,y} โช {z}.
w:
T
x:1 y:1 u:2 v:
w:
T'
z:
u:2 v: