In: Computer Science
Say that the input for an Huffman coding contains 256 letters. Each appearing the the same number of times. (a) If we choose to code all letters by codes of the same length, what is the number of bits required? (b) Is the Huffman code better than the code of the first item?
Solution:
=>Huffman coding is used.
=>Number of letters = 256
=>Each letter appears same number of times.
(a)
Explanation:
=>All letters are coded by codes of same length so it means fixed encoding is used.
Calculating number of bits:
=>Number of bits to represent 256 characters = log2(256)
=>Number of bits to represent 256 characters = log2(2^8)
=>Number of bits to represent 256 characters = 8 bits
=>Total number of bits = total letters*each letter code's length
=>Total number of bits = 256*8 bits
=>Total number of bits = 2048 bits
(b)
Explanation:
=>As each letter has same frequency so all the letters will be kept at the leaf level in the huffman tree.
=>Total number of bits required in this case = same as the total number of bits required in fixed length encoding
=>Total number of bits required in this case = 2048 bits
=>Hence we can say that huffman code is not better than the code of first item in this case.
I have explained each and every part with the help of statements attached to the answer above.