Building a Huffman tree