Reputation: 11
I have been given the alphabet with its frequencies, like:
e: 17,4
n: 9,78
j: 0,27
and so on. For every letter of the alphabet. My question is:
Is there any program/applet that generates me a huffman tree with these given frequencies? The only generators I have found do use Text as input.
Maybe one of you might have an idea! Thank you very much!
Upvotes: 1
Views: 219
Reputation: 112394
If you have source code that takes letters, computes their frequency, and then applies the Huffman algorithm, then you can simply strip the part that computes the frequency and use the Huffman algorithm directly on the frequencies.
Otherwise, you can write the Huffman algorithm yourself. It is one of the simplest and most elegant algorithms out there, so everyone should implement it themselves at least once. You sort the frequencies and pick the two lowest. Those two symbols are joined as the first branch of the tree. Reinsert the sum of the frequencies in the sorted list. Repeat until all of the symbols are part of the tree.
Upvotes: 1