当前位置:网站首页>Data Agencies - Huffman Trees
Data Agencies - Huffman Trees
2022-08-09 00:13:00 【Biao Biao_】
What is a Huffman tree?
Let's first look at the definition of Huffman tree:
Huffman tree (Huffman Tree) is in the case of leaf nodes and weights determined,The binary tree with the smallest weighted path length is also called the optimal binary tree.
When I saw this definition, I was stunned. What leaf nodes and weights are good, so what does the path mean, the way from one node to another?And what does the weighted path length mean?
What is a path?
In a tree, all the nodes passed from one node to another are called paths between two nodes.
In the above binary tree, from root node A toThe path of leaf node H is A, B, D, H.
So the path length is 3, which is A=>B=>D=>H.
What is the weighted path length of a node?
The weighted path length of the nodeRefers to: the product of the weight of the node * the path length from the root node of the tree to the node.
That is 1x3=3.
Then the weighted path length of the tree is: the sum of the weighted path lengths of all leaf nodes
that is 1x3+2x3+3x2+4x2+5x2=33
Huffman tree construction
Assuming there are 5 leaf nodes and the weights are 1, 2, 3, 4, and 5 in order, how to construct a Huffman tree, that is, the tree with the smallest weighted path length?





Pseudo code implementation:
See the above mentioned every timeWhen the two nodes with the smallest value are merged, is it possible to think of the min heap in an instant? We store the weights in the min heap, and just take the root node each time.Screenshot directly here

Huffman coding is actually Huffman treeAn application
It is an unprefixed encoding.No confusion when decoding.It is mainly used in data compression, encryption and decryption, etc. 
边栏推荐
- 穿越派·派盘(WebDAV)解决OmniFocus同步问题
- VsCode configures your favorite fonts and backgrounds. Mom no longer worries about my boring code writing.
- 最新7篇数据科学/深度学习/CNN/知识图谱/文本匹配等中英文综述论文推介(附下载)
- Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [33,755] milliseco
- 穿越派·派盘V3.14发版啦!
- 多种决策树及应用 笔记
- ScreenSpace-ShadowMap(屏幕空间的阴影映射技术)
- 透明度混合-Blend
- 整流十二 -有效值、平均值、瞬时值、幅值的关系以及相关方法
- 矩阵乘法总结
猜你喜欢
随机推荐
Dart高级(一)——泛型与Json To Bean
逐片元-兰伯特光照模型
ImportError: cannot import name downsample
最新7篇数据科学/深度学习/CNN/知识图谱/文本匹配等中英文综述论文推介(附下载)
nlp 评论分类实现总结
vspm虚拟串口调试
AcWing 173 矩阵距离 bfs
遮罩纹理-MaskTexture
JS data types
2017年8月历史文章汇总
穿越派·派盘+KeePass = 最安全的私人密码管理方案
牛客多校8 补题
移动web开发-插件&事件篇
Risk Control Modeling IV: Logistic Regression Scorecard Development
2017年9月历史文章汇总
Task19_14_最长公共前缀
WeChat applet console error - summary 】 【
牛客练习赛88 补题
菲涅尔反射
After the sessionStorage value is changed, the value obtained by the page using window.sessionStorage.getItem() will not be updated









