there is a problem in your code when we use a word contains a letters redundancy example: MOROCCO , we will find that the first c will have a different code of second c and in addition one will be a beginning of the other therefore a violation of the huffman algorithm which is a prefix code