Optimal Huffman Tree
Input: Probabilities p1, p2, ... , pm for symbols a1, a2, ... ,am, respectively.
Output: A Huffman tree that minimizes the average number of bits to code a symbol. That is, minimizeswhere ri is the length of the path from the root to ai.