简体   繁体   中英

What happens if we are inconsistent while creating Huffman Tree?

Why can't we be inconsistent while creating Huffman Tree ie 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM