encoding using Huffman tree