Reputation: 369
Why can’t we be inconsistent while creating Huffman Tree i.e sometime make the higher frequency node left child and sometimes right I know per convention, we have to decided beforehand if we would assign the larger node to the left or right child and we have to maintain that order. Why is this have to be fixed?
Putting it left or right randomly doesn't influence the weight of the new node, or the height, so nothing really changes, right?
Upvotes: 3
Views: 192
Reputation: 14379
Correct.
The codes 00
, 11
, 10
, and, 01
, carry same weight from the perspective of Huffman encoding. So putting a node on the left vs on the right will change the code but it will not change the length of the Huffman code.
The goal with Huffman Tree is to come up with an encoding such that the most frequent term has the smallest length code. Putting the larger node on the left or right is immaterial.
Upvotes: 2