1. Intro
Under the background of the current quality education, the academic grades of primary school have been changed into the vague words of excellent, good, pass and fail, and no longer communicate the specific scores.
You can use code to represent the following:
if (a <)
System.out.print ("fail");
else if (a <)
System.out.print ("Pass");
else if (a <)
System.out.print ("good");
else
System.out.print ("excellent");
A cursory look at this is no problem, but a good test paper most students focus on "good", and the above procedures need to judge two times to "good", input a large amount of time, in the algorithm efficiency is actually a problem. So the following improvements should be made (①->②):
2. Huffman tree Definition and principle
We first simplified the above diagram into a leaf node with a weighted two-tree (note: The number of connections between tree nodes is called the right, Weight).
The path length of the ① node: the number of connections from the root node to the path of the node.
Path length of the ② tree: The sum of the path lengths of each leaf node in the tree.
③ node Weighted path length: The product of node path length and node weight value.
The weighted path length of the ④ tree: WPL (weighted path length) is the sum of the weighted path lengths of all the leaf nodes in the tree.
※ The smaller the value of the WPL, the better the performance of the two-fork tree, the optimal binary tree is also called Huffman Tree.