Can the left subtree's frequency bigger than the right?

- 9,674
- 9
- 41
- 79
-
I can't see any reason for doing this with a normal Huffman Tree. Yet, if you're talking about an Adaptive Huffman Tree, that's a different story. – Muhammad Yaseen Khan Jun 29 '16 at 08:33
1 Answers
(The title asks a positive question, and the body asks the corresponding negative question, so I can't answer yes or no!)
You can pick left and right however you like, or equivalently assign 0 and 1 as you like to left and right branches, and you will still have an optimal code. All that changes are the code values. There are 128 different sets of code values that you can generate from that tree.
In actual applications, the lengths of each code are all that is derived from the tree, at which point the tree is discarded. You can then assign code values using a canonical approach. This picks a specific one of the 128 possible codes. Then the receiver only needs to know the code length for each symbol in order to decode.
By the way, there is one other variation in the tree that is possible, which is that you could pick either D or L to pair with U, since they have the same frequency. That would give two different trees, though since the resulting code lengths are the same, there is still just the one canonical code.

- 101,978
- 13
- 118
- 158