Havermann, a man who has appeared in almost every book that tells data structures, he must not have told me more. This time to explain the construction of the Havermann tree and the basic principles of Havermann coding, what is the use? Don't worry, learn to create a Havermann tree first.
Haverman is also known as the optimal binary tree, the optimal binary tree is the right path length WPL the smallest two-fork tree, then we have to understand several concepts:
1. Path length: The branch from one node to another in the tree forms the path of these two nodes, and the number of branches on the path is called the path length.
2. Tree path length: From the root to each node of the path length of the sum, we call the complete binary tree is the shortest path length of the two-fork tree.
3. The length of the tree's weighted path: If a weight is assigned to each leaf node of the tree, then the length of the tree's weighted path equals the sum of the path length of the root node to all the leaf nodes and the product of the leaf node weights.
So how do we determine if a tree is the best binary tree, look at the following tree
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/
Their weighted lengths were:
wpl1:7*2+5*2+2*2+4*2=36
Wpl2:7*3+5*3+2*1+4*2=46
Wpl3:7*1+5*2+2*3+4*3=35
Obviously, the third tree has the shortest path, which is what we call the optimal binary tree (Haverman), its construction method is very simple, in order to select the smallest weights of the node placed at the bottom of the tree, the smallest two connections constitute a new node, it should be noted that the composition of the new node weight should be equal to the sum of the weights of these two nodes, Then we're going to put this new node back in the node where we need to make the tree, so that the Havermann tree, all the nodes where the information is stored, is on the leaf node.
The following picture shows you the construction process of the Havermann tree: