Building huffman tree