在创建霍夫曼树时,哪个节点在添加权重时向左或向右移动 [英] Which node go in left or right on addition of weight while huffman tree creation

查看:78
本文介绍了在创建霍夫曼树时,哪个节点在添加权重时向左或向右移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个霍夫曼树,但通过阅读互联网上的几个链接使我有些困惑.有些在左侧添加一些(按权重)较大的子节点,有些在右侧添加一些子节点.

I am trying to create a Huffman tree and i am bit confused by reading several links on internet. Some add the greater(in terms of weight) child nodes in left or some on right.

所以我的问题:

(1)在左边或右边添加节点是否真的很重要?

(1)Is it really a matter that where to add the nodes(in left or right) ?

(2)我可以在左"中添加权重较大的节点,还是在左"中添加权重较低的节点?

(2) May i add node with greater weight in right or lower weight in Left ?

感谢您的帮助.

推荐答案

只要您保持一致,就没有任何区别.

As long as you're consistent, it makes no difference.

要么将 all 放到左孩子的较低权重上,要么全部放右孩子的权重较高,反之亦然.

Either you put all the lower weights on left children and all the higher weights on right children, or vice-versa.

在最底行, left right 将仅是代码中的变量名,没有任何物理意义.

At the bottom line, left and right will only be variable names in your code, with no physical meaning whatsoever.

更新:

如果不一致,则生成的霍夫曼树不一定会产生使用霍夫曼压缩算法为给定输入可实现的最佳压缩.

If you are not consistent, then the resulting Huffman tree will not necessarily yield the best possible compression that can be achieved for the given input using the Huffman compression algorithm.

这篇关于在创建霍夫曼树时,哪个节点在添加权重时向左或向右移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆