Valid Huffman Codes?

前端 未结 1 1340
梦谈多话
梦谈多话 2021-01-24 21:56

I\'m trying to solve a Huffman Coding problem, but I\'m not completely sure I understand the topic completely. I am trying to figure out if the following are is a valid Huffman

相关标签:
1条回答
  • 2021-01-24 22:42

    No. A Huffman code is a prefix code, which means that no code can be a prefix of any other code. In your example, A is a prefix of B, and C is a prefix of both D and E.

    A valid prefix code would be:

    A: 0
    B: 10
    C: 11
    

    That's as far as you can go with codes of length 1, 2, and 2. Any other codes would be a prefix of those. It is not possible to have a prefix code with lengths 1, 2, 2, 3, and 3.

    This is a valid prefix code for five symbols:

    A: 0
    B: 10
    C: 110
    D: 1110
    E: 1111
    

    as is this:

    A: 00
    B: 01
    C: 10
    D: 110
    E: 111
    
    0 讨论(0)
提交回复
热议问题