Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens if we are inconsistent while creating Huffman Tree?

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?

like image 649
Surbhi Jain Avatar asked Dec 06 '25 07:12

Surbhi Jain


1 Answers

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.

like image 54
displayName Avatar answered Dec 12 '25 06:12

displayName



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!