Question

I have the following values

Event  Probability   
 A      0.3  
 B      0.3 
 C      0.13     
 D      0.12      
 E      0.1  
 F      0.05    

My Tree looks something like this

                                 [1]
                              /0     \1
                            [.4]    [.6]
                          0/   \1    /0   \1
                       [.27][.13] [.3] [.3]
                     0/   \1
                  [.15]  [.12]
                 0/    \1
                [.1]  [.05]

i am sorry for the bad representation but thats the best i could do.

I am following this example online but my values are not the same. I am unable to understand what i am doing wrong? If someone could guide me in the right direction.

Example: http://www.math.upenn.edu/~deturck/m170/wk7/lecture/huffman/huffman.html

My values comes to something like this:

A = 10 
B = 11

but in the example the value for A = 00, and for B = 01

Was it helpful?

Solution

I think one possible issue here is in the leftmost subtrees. You correctly merged together the trees with probabilities 0.05 and 0.10 together to form a tree of net probability 0.15. However, at this point the trees available have probabilities

0.3    A
0.3    B
0.15   EF
0.13   C
0.12   D

The Huffman encoding algorithm always chooses the two trees with the lowest total probabilities to merge together, so the next step would be to merge C and D. From your tree, it seems like you instead merged EF and D, which is incorrect.

Try merging using this other approach and see if that resolves things.

Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top