Introduction of Huffman Tree

Huffman Tree, Chinese name is Huffman tree or Hoffman tree, which is the optimal binary tree.

Definition: Given a weight of n as n leaf nodes, construct a binary tree. If the length of the weighted path of the tree is the smallest, the tree is called a Huffman tree. There are several strange concepts involved in this definition. Below is a Huffman tree. Let's look at the graph solution.

Huffman algorithm understanding and principle analysis, constructing Huffman tree algorithm

(1) Path and path length

Definition: The path between a child or grandson node that can be reached from a node down in a tree, called the path. The number of branches in a path is called the path length. If the number of layers of the root node is 1, the path length from the root node to the L-th layer node is L-1.

Example: The path lengths of 100 and 80 are 1, 50 and 30 are path lengths 2, and 20 and 10 path lengths are 3.

(2) The weight of the node and the length of the weighted path

Definition: If a node in a tree is assigned a value with a meaning, this value is called the weight of the node. The weighted path length of a node is the product of the path length from the root node to the node and the weight of the node.

Example: The path length of node 20 is 3, and its weighted path length = path length * weight = 3 * 20 = 60.

(3) The length of the weighted path of the tree

Definition: The length of the weighted path of the tree is defined as the sum of the lengths of the weighted paths of all leaf nodes, denoted WPL.

Example: In the example, the tree's WPL = 1*100 + 2*50 + 3*20 + 3*10 = 100 + 100 + 60 + 30 = 290.

Compare the two trees below

Huffman algorithm understanding and principle analysis, constructing Huffman tree algorithm

The two trees above are trees with {10, 20, 50, 100} as leaf nodes.

The tree on the left is WPL=2*10 + 2*20 + 2*50 + 2*100 = 360

Tree on the right WPL=290

The WPL of the tree to the right of the tree WPL on the left. You can also calculate cases other than the above two examples, but in fact the tree on the right is the Huffman tree corresponding to {10, 20, 50, 100}. At this point, you should have a certain understanding of the concept of the Huffman tree. Let's look at how to construct a Huffman tree.

Liquid Crystal Display For Instrument

Liquid Crystal Display For Instrument,Large Industrial Precision Lcd Display,Small Industrial Body Thin Lcd Display,Precise Liquid Crystal Display

Dongguan Yijia Optoelectronics Co., Ltd. , http://www.everbestlcdlcm.com