-1

I am learning Huffman coding and trying to find the following answers:

  1. Can Huffman tree ever be a list? If yes, then in which case? If no, then why?
  2. In Huffman coding, is it possible to have exactly two symbols with the longest codeword length? If yes, then in which case?
  • how you "note down" that tree doesn't matter. You can represent any tree as a list. In fact, all real-world Huffman encoders use tables, not trees. – Marcus Müller Dec 11 '21 at 18:40
  • also, we really can't tell you where you're stuck in answering these questions, which quite clearly a learning assignments to you, not us. – Marcus Müller Dec 11 '21 at 18:40

1 Answers1

0

Can Huffman tree ever be a list? If yes, then in which case? If no, then why?

Well, not a list exactly, but it can be a tree where all left children are leaves and the only right-node leaf will be on the deepest node. This happens when one symbol has a higher probability than the sum of every other node combined, and then at the next level the most probable node has a higher score than the sum of the rest, and so on, as in this example:

   -
  / \
0.5  -
    / \
 0.25  -
      / \
    .10  -
        /  \
       .2  .1

(this shows just the probabilities, not the corresponding symbols, which are arbitrary for this discussion)

Of course for this to happen for, say, a 256-symbol tree, the population count for the most common symbol would need to be astronomically large.

In Huffman coding, is it possible to have exactly two symbols with the longest codeword length? If yes, then in which case?

Sure - in fact that's exactly what happens in the tree from above:

   -
  / \
 0   - (1 - non-leaf)
    / \
 10    - (11 - non-leaf)
      / \
    110  - (111 - non-leaf)
        /  \
      1110  1111