huffmanTree build and huffman Coding

huffMan Tree:
Imagine that here is one article , which contains 27 'A' , 8 'B' ...and 5 'F' :
A 27 , B 8 , C15, D15, E30 ,F5


So now build a Huffman tree
(1)take first TWO numbers , (2)construct one tree ,left value is smaller than right side(3) then insert the ROOT into the sequence, (3)then ORDER the numbers .


1> order the numbers .
F5 , B8, C15, D15, A27, E30


2>


P13 ,C15 ,D15 ,A27 ,E30
/ \
F5 B8


3>


P28 D15 A27 E30

/ \

P13 C15

/ \

F5 B8



4>
D15 A27 P28 E30
/ \
P13 C15
/ \
F5 B8


5>


P42 P28 E30
/ \ / \
D15 A27 P13 C15
/ \
F5 B8


6> P28 E30 P42
/ \ / \
P13 C15 D15 A27
/ \
F5 B8


7>
P58
/ \ P42
P28 E30 / \
/ \ D15 A27
P13 C15
/ \
F5 B8


8> P100
/ \
/ \
P42 P58
/ \ / \
D15 A27 P28 E30
/ \
P13 C15
/ \
F5 B8




now let's say Left EDGE is 0 , right EDGE is 1
so for gets the huffman codes :


A:01
B:1001
C:101
D:00
E:11
F:1000


so the codes should be
01100110100111000


then analysis the sequence :
1>take each 0/1 , start from root search node ,till can not reach
2>remove the 0/1 already taken
3>loop



then will get huffman tree.




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值