Generating Huffman trees