-2

Huffman encoding uses probability of occurrences of each value, to construct a tree where the values are the leaves. The path length from root to a leaf is least for most probably occurring values.

Is the tree constructed (ignoring the assignment of 0s and 1s to left and right) always balanced? (Balanced: depth of left and right subt-ree of every node differ at most by 1)

Support with mathematical proof would be much appreciated :)

Amogh
  • 19
  • 4
  • Have you tried constructing one that isn't balanced? If you can do it, then you have a quick and easy proof for no. If you can't do it, then it would add value to the question. – domen Jan 25 '16 at 10:27
  • 6
    The whole idea of a Huffman tree is that it is unbalanced and "heavier" (i.e. deeper) on the side where the less frequent nodes are. – M Oehm Jan 25 '16 at 12:19
  • I downvoted your question because it shows an obvious lack of any effort on your part to even understand the first thing about the topic. We're not here to do your thinking for you. – Jim Mischel Jan 25 '16 at 17:12

3 Answers3

2

No. Consider the frequencies 1, 1, 2, 4. It will generate a tree like the following:

huffman tree

Juan Lopes
  • 10,143
  • 2
  • 25
  • 44
1

For a more mathematical answer, you could say that if all the frequencies are different powers of two, the huffman tree will be unbalanced.

0

No. Even the basic examples shown, for example, on the Wikipedia page, have encodings with three different lengths in a single tree.

Svante
  • 50,694
  • 11
  • 78
  • 122