Reputation: 1082
I have encountered what seems like a Huffman tree and a string of data that I need to decode.
So my question is: How to decode this string using the Huffman Tree?
Upvotes: 0
Views: 970
Reputation: 6145
The tree in the image is supposed to be continued. After B comes C,D... and after O comes P,Q... This means C is coded 01110, D is coded 011110, P is 11110 ...
Knowing that the string contains 'the' and 'is', there is a high chance that the whole string is started by 'the'.
With this tree, 'the' is coded 111111110 0111111110 0111110.
Seeing that, it is easy to deduce the decimal encoding, since it happens to perfectly match this. "111111110 0111111110 0111110" is 8x1 + 0 + 0 + 8x1 + 0 + 0 + 5x1 + 0. In short, 80080050. A number indicates a sequence of 1, and 0 means a 0. This also means that 10 is ambiguous, but well, there is only 2 possibilities.
Now you can decode the rest.
Upvotes: 1