新闻资讯 茶油品牌 供应商 营销展会 代理加盟 茶油收购
首页> 苗木百科> 详情

给定权值(5,10,12,15,30,40),构造相应的哈夫曼树.要求写出构造步骤

绿色山茶油 2022-01-20 15:17 编辑:niming 6148阅读

按权值大小排列后 5,10,12,15,30,40
只要按照将最小的两个合并, 合并后的值再入列中(最小的两个出列), 至到列中只有一个值.
得到序列5+10=15, (12,15,15,30,40)
[5]`````[10]
\`````/
\```/`
\`/
` `(15)`
从(12,15,15,30,40)找两个最小的12+15=27
[5]`````[10]````````[12]``````[15]
``\`````/`````````````\``````/
` `\```/` ``````````` `\````/`
````\`/`````````````````\``/
````(15)````` ````````(27)`
依次从新的序列中取2个想加和最小的。
(15,27,30,40)-----取15+27=42;
(30,40,42)---------取30+40=70;
(42,70)-------------取42+70=112;
(112)就剩一个终止。

[5]`````[10]`[12]``````[15]
``\`````/``````\``````/
`0`\```/`1`````0\````/`1
````\`/``````````\``/
````(15)````` (27)``[30]`````[40]
``````\`````` /`````````\``````/
`````0`\```` /`1````````0\````/`1
````````\`` /`````````````\``/
```````` (42)````````````` (70)``````
```````````\`````` ````````````/
``````````0`\``````` ```````/
`````````````\ ```````````/
`````````````(46)``````````1/`
````````````````\``````````/``
```````````````0`\````````/``
``````````````````\``````/``
````````````````````(112)

图真不好画,详细可以参考

感觉不错,赞哦! (0)
下次努力,加油! (0)
标签说明:
网友评论仅供其表达个人看法,并不表明本站立场。
评论
相关阅读