給定權值 7,18,3,32,5,26,12,8 ,構造相應的哈夫曼樹

2022-06-09 13:26:49 字數 3187 閱讀 6382

1樓:**的可樂

這還不夠細?

3+5=8,此時序列為8 7 8 12 18 26 32

7+8=15,此時序列為15 8 12 18 26 32

8+12=20,此時序列為15 20 18 26 32

……每一步都挑最小的兩個相加。

圖見下面。

多看書,baidu上不好畫圖,打這些東西很累。

------------------

原答題者:plause

按權值大小排列後 3 5 7 8 12 18 26 32

只要按照將最小的兩個合併, 合併後的值再入列中(最小的兩個出列), 至到列中只有一個值.

按上面要求構造哈夫曼樹如下:

/////樹列完後, 可取左樹編碼 為0, 右為 1, (左為 1, 右為 0 亦可)

[3]`````[5]`````````[7]``````[8]

``\`````/`````````````\``````/

`0`\```/`1```````````0`\````/`1

````\`/`````````````````\``/

````(8)`````[12]````````(15)`````[18]

``````\``````/`````````````\``````/

`````0`\````/`1```````````0`\````/`1

````````\``/`````````````````\``/

````````(20)``````[26]```````(33)``````[32]

```````````\``````/`````````````\``````/

``````````0`\````/`1```````````0`\````/`1

`````````````\``/`````````````````\``/

`````````````(46)`````````````````(65)

````````````````\`````````````````/

```````````````0`\```````````````/`1

``````````````````\`````````````/

```````````````````````(111)

則按上面的樹可得到各權值所對應的編碼:

//// 其編碼是從樹頂到該權值點所經過的 1 或 0 的序列

[`7]:``1`0`0`0

[18]:``1`0`1

[`3]:``0`0`0`0

[32]:``1`1

[`5]:``0`0`0`1

[26]:``0`1

[12]:``0`0`1

[`8]:``1`0`0`1

2樓:獸獸小強

每次都 是找最小的2個權值 然後構造新的節點 接著帶繼續做 知道只剩一個節點

3樓:韶壁

剛學過,可是我還是不會,不好意思哦

給定權值(7,18,3,32,5,26,12,8),構造相應的哈夫曼樹.

4樓:匿名使用者

按權值大小排列後 3 5 7 8 12 18 26 32

只要按照將最小的兩個合併, 合併後的值再入列中(最小的兩個出列), 至到列中只有一個值.

按上面要求構造哈夫曼樹如下:

/////樹列完後, 可取左樹編碼 為0, 右為 1, (左為 1, 右為 0 亦可)

[3]`````[5]`````````[7]``````[8]

``\`````/`````````````\``````/

`0`\```/`1```````````0`\````/`1

````\`/`````````````````\``/

````(8)`````[12]````````(15)`````[18]

``````\``````/`````````````\``````/

`````0`\````/`1```````````0`\````/`1

````````\``/`````````````````\``/

````````(20)``````[26]```````(33)``````[32]

```````````\``````/`````````````\``````/

``````````0`\````/`1```````````0`\````/`1

`````````````\``/`````````````````\``/

`````````````(46)`````````````````(65)

````````````````\`````````````````/

```````````````0`\```````````````/`1

``````````````````\`````````````/

```````````````````````(111)

則按上面的樹可得到各權值所對應的編碼:

//// 其編碼是從樹頂到該權值點所經過的 1 或 0 的序列

[`7]:``1`0`0`0

[18]:``1`0`1

[`3]:``0`0`0`0

[32]:``1`1

[`5]:``0`0`0`1

[26]:``0`1

[12]:``0`0`1

[`8]:``1`0`0`1

給定一組權w={3,5,10,12,15,22} 構造哈夫曼樹,並計算它的帶權外部路徑長度wpl。

5樓:

從根節點到各個葉節點的路徑長度與對應葉節點權值的乘積之和22的路徑長度是1

10、12、15的路徑長度是3

3、5的路徑長度是4

所以wpl = 22 + (10 + 12 + 15) * 3 + (3 + 5) * 4 = 22 + 111 + 32 = 165

6樓:不要找我好不

wpl=(3+5)*4+10*3+(12+15+22)*2=160

7樓:南槿有懷

160, 看下面解釋

給定一組權值[8,4,5,2,10],以低權值節點為左子樹畫出由此生成的哈夫曼樹,並寫出每個權值對應的... 30

價格權值是什麼意思,權值是什麼意思

所謂的 權值就是 在整個投標過程中佔有的投標總得分的比重。在數學領域,權值指加權平均數中的每個數的頻數,也稱為權數或權重。對於多位數,處在某一位上的 l 所表示的數值的大小,稱為該位的位權。在計算機資料結構領域,權值是樹或者圖中兩個結點路徑上的值,這個值表明一種代價,如從一個結點到達另外一個結點的路...

若有字元a,b,c,d,e,f,g,h的頻度權值分別為

仔細看了一copy下,這裡的圖根編碼不一致,最後2 5加起來的值是7 跟 7位置換一下 即部分左子樹改為如下95 59 29 30 14 15 7 7 2 5 這樣,b就是00001,g是0001 f是000000你上面的哈夫曼樹 沒有錯,因為同樣大小的權值點,沒有規定誰左誰右 編碼就是你說的b是0...

ecel隨機數取值後怎麼在權的值後在加範圍

在單元格里輸入 8 20 rand 表示會產生一個8 28的數 即18為中心,不會小於8,不會大於28 如果你的意思是要整數.改為 8 int 21 rand 說明 rand 是產生一個大於0,小於1的隨機數,所以取整就要21 rand 會生成0 20的整數.隨機數的生成可以用公式 int rand...