# Huffman tree generation if the frequency is same for all words

Can a valid Huffman tree be generated if the frequency of words is same for all of them?

Example :

Value     | Frequency
--------------------
Google    | 2
Yahoo     | 2
Microsoft | 2
Amazon    | 2


## 2 Answers

Yes. When creating a Huffman tree, if you ever find you need to select from a set of objects with the same frequencies, then just select objects from the set at random - it will have no effect on the effectiveness of the algorithm.

Of course, one might question why you're bothering to build a Huffman tree if you know all the frequencies are the same - I can tell you what the optimal encoding is.

Yes. Whenever identical frequencies occur, the Huffman procedure will not result in a unique code book, but all the possible code books lead to an optimal encoding.