# First mini-project: Binary preﬁx codes and Huffman’s codes solution

\$24.99

Original Work ?

## Description

5/5 - (1 vote)

I. INTRODUCTION A binary code is a representation of set of symbols that assigns a distinct bit string—a code word—to every symbol in the set. A binary preﬁx code is a binary code where no bit string of the code is a preﬁx of another. With a binary preﬁx code, we can unambiguously decode any string of bits without marks separating the code words. A binary preﬁx code can be constructed from any two-tree with the symbols positioned at the leaves of the tree. Associate a 0 to the left child and a 1 to the right child of every node with children. The code word of a symbol is the sequence of bits read along the unique path from the root to the leaf holding the symbol. Figure 1 shows a preﬁx code and the two-tree from which is was generated. Suppose that we are given a set of n symbols together with their relative frequencies of occurrence. Let fi and si denote the relative frequency and code word length, respectively, of symbol ai, for 1 ≤ i ≤ n. The symbols are encoded with a binary preﬁx code. The average length of the code is given by n ∑
i=1
fisi. (1)
An optimal binary preﬁx code is a preﬁx code of minimum average length. David Huffman, in 1951, invented a method to derive such codes. In his honor, optimal binary preﬁx codes bear his name. Today, Huffman’s codes are
symbol code word
a 00
b 010
c 011
d 10
e 110
f 111
a d
fe
Code Two-tree representa on
b c
Fig. 1. A preﬁx code for the set of symbols {a,b,c,d,e}.
2
symbol freq. code word
a 0,22 011
b 0,03 0000
c 0,14 001
d 0,14 010
e 0,41 1
f 0,06 0001
Code Two-tree representa on
b f