Huffman tree (Homan tree, and optimal binary tree)
Huffman tree (Homan tree, and optimal binary tree)
Flyfish 2015-8-1
The Huffman tree has different translations, so there are other names:
Define reference from Yan Weimin Data Structure
Path
The branches from one node in the tree to another constitute the path between two nodes.
Path Length
The number of branches on the path is called the path length.
Tree path length
The tree path length is the sum of the path lengths from the root node to each node.
Length of the weighted path of a node
The length of the weighted path of a node is the product of the path length from the node to the root node and the permission on the node.
Length of the tree's weighted path
The length of a tree's weighted path is the sum of the length of the weighted path of all leaf nodes in the tree. It is generally recorded as WPL.
Huffman tree
Assume there are n weights { W1, w2 ,... Wn }, Construct a binary tree with n leaf nodes, with each leaf node having the right Wi The binary tree with the minimum length of WPL is called the Huffman tree.
Assume that there is a character string, and each character appears as follows:
A: 5
B: 15
C: 40
D: 30
E: 10
Sort characters in ascending order to form an ordered sequence.
Bottom-up creation process
Step 1
Step 2
Step 3
Step 4
Constructed <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCjxwPjxzdHJvbmc + uMXE7rK5s + Q8L3N0cm9uZz48L3A + DQo8cD48aW1nIGFsdD0 = "here write picture description" src = "http://www.bkjia.com/uploads/allimg/150803/04203L0Q-5.png" title = "/>