1. Tree path length
The tree path length is the sum of the path lengths from the root to each node in the tree. In a binary tree with the same number of nodes, the path length of the Complete Binary Tree is the shortest.
2.
The length of the weighted path (weighted path length of tree, abbreviated as WPL)
Node permission: in some applications, assign a node in the tree
A real number.
The length of the weighted path of a node: the product of the path length between the node and the root node and the permission on the node.
The length of the weighted path (weighted
Path Length of tree): defines the sum of the length of the weighted path of all leaf nodes in the tree, which is usually recorded:
Where:
N indicates the number of leaf nodes.
WI and Li indicate the weight of the leaf node KI and the path length between the root node Ki.
The length of the tree's weighted path is also known as the cost of the tree.
3. optimal binary tree
Or the User-Defined tree
In wl, W2 ,..., Among all the Binary Trees composed of N leaves of WN, the binary tree with the minimum length of the weight path (that is, the minimum cost) is called the optimal binary tree or the Harman tree.
[Example] Four Leaf nodes A, B, C, and D are given with weights 7, 5, 2, and 4, respectively. Construct the three Binary Trees (and many other trees) as shown in. Their weighted path lengths are:
(A) WPL = 7*2 + 5*2 + 2*2 + 4*2 = 36
(B) WPL = 7*3 + 5*3 + 2*1 + 4*2 = 46
(C) WPL = 7*1 + 5*2 + 2*3 + 4*3 = 35
The WPL of the (c) tree is the smallest, which can be verified.
Note:
① When the weights on the leaves are the same, the full binary tree must be the optimal binary tree; otherwise, the full binary tree is not necessarily the optimal binary tree.
② In the optimal binary tree, the higher the weight, the closer the leaves are from the root.
③ The form of the optimal binary tree is not unique, and the WPL is the smallest.