Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Huffman coding two characters as one

I need huffman code(best in python or in java), which could encode text not by one character (a = 10, b = 11), but by two (ab = 11, ag = 10). Is it possible and if yes, where could i find it, maybe it's somewhere in the internet and i just can'd find it?

like image 829
Adomas Avatar asked Apr 14 '26 13:04

Adomas


1 Answers

Huffman code doesn't care about characters, it cares about symbols. Generally, it is used to encode the alphabet / other single characters, but can very easily be generalized to encode strings of characters. Basically, you would just take an existing implementation and allow symbols to be strings rather than characters. A leaf node would then correspond to a list of strings.

like image 98
danben Avatar answered Apr 16 '26 01:04

danben