1.3k views

Suppose the letters $a, \,b, \,c, \,d, \,e, \,f$ have probabilities $\frac{1}{2}, \frac{1}{4}, \frac{1}{8}, \frac{1}{16}, \frac{1}{32}, \frac{1}{32}$, respectively.

Which of the following is the Huffman code for the letter $a, \,b, \,c, \,d, \,e, \,f$?

1. $0$, $10$, $110$, $1110$, $11110$, $11111$

2. $11$, $10$, $011$, $010$, $001$, $000$

3. $11$, $10$, $01$, $001$, $0001$, $0000$

4. $110$, $100$, $010$, $000$, $001$, $111$

edited | 1.3k views

Based on the probabilities, we can say the probable frequency of the letters will be

$16$, $8$, $4$, $2$, $1$, $1$

Now, the Huffman tree can be constructed as follows:

So, A is the answer for $76$.

https://www.siggraph.org/education/materials/HyperGraph/video/mpeg/mpegfaq/huffman_tutorial.html

answered by Veteran (346k points)
edited by

Is there any constraint on where to put the two same weighted values according to them being single and composite? Is the following Huffman tree correct too?

@habedo007  it is correct.You will also get the same values,it just your tree can have left and right encoding of 1,0 opposite but it is also correct

We get the following Huffman Tree after applying Huffman coding Algorithm The idea is to keep the least probable characters as low as possible by picking them first.

The letters a, b, c, d, e, f have probabilities
1/2, 1/4, 1/8, 1/16, 1/32, 1/32 respectively.

1
/   \
/     \
1/2    a(1/2)
/  \
/    \
1/4  b(1/4)
/   \
/     \
1/8   c(1/8)
/  \
/    \
1/16  d(1/16)
/  \
e    f
The average length = (1*1/2 + 2*1/4 + 3*1/8 + 4*1/16 + 5*1/32 + 5*1/32)
= 1.9375 

http://www.geeksforgeeks.org/gate-gate-cs-2007-question-77/

answered by (147 points)