문제

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

도움이 되었습니까?

해결책

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!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top