Question

In: Computer Science

Say that the input for an Huffman coding contains 256 letters. Each appearing the the same...

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?

Solutions

Expert Solution

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.


Related Solutions

Write a program in C++ (parking.cc) that reads a group of input lines. Each line contains...
Write a program in C++ (parking.cc) that reads a group of input lines. Each line contains an A for arrival or a D for departure, which is terminated by a :, and a license plate number, which is terminated by a :. The program should print a message each time a car arrives or departs. When a car arrives, the message should specify when the garage is full. If there is no room for a car, the car simply leaves....
Company produces and sells 90,000 boxes of specialty foods each year. Each box contains the same...
Company produces and sells 90,000 boxes of specialty foods each year. Each box contains the same assortment of food. The company has computed the following annual costs: Cost Item Total Costs Variable production costs $630,000 Fixed production costs 470,000 Variable selling costs 180,000 Fixed selling and administrative costs 170,000 Total costs $1,450,000 Mendenhall normally charges $ 30 per box. A new distributor has offered to purchase 9,000 boxes at a special price of $ 27 per box. Mendenhall will incur...
Suppose we have an input file that contains information about how many hours each employee of...
Suppose we have an input file that contains information about how many hours each employee of a company has worked. The file looks like the following (Employee's name, Hours): John 6.5 9.5 7.25 9 8.55 Oscar 12.5 13.5 14 16 18.75 Judith 7 7 7 ••• Construct a program that reads this file and calculates the total number of hours worked by each individual. Make sure that the program handles each specific exception that could occur.' python
e Elixer Drug Company produces a drug from two ingredients. Each ingredient contains the same three...
e Elixer Drug Company produces a drug from two ingredients. Each ingredient contains the same three antibiotics, in different proportions. One gram of ingredient 1 contributes 3 units, and 1 gram of ingredient 2 contributes 1 unit of antibiotic 1; the drug requires 6 units. At least 4 units of antibiotic 2 are required, and the ingredients contribute 1 unit each per gram. At least 12 units of antibiotic 3 are required; a gram of ingredient 1 contributes 2 units,...
Python coding: Write code for each method listed. Input Text File Format: username|Firstname|Lastname|password|accountnumber|balance jh123|Jane|Hudson|45678910|AB45|900 ah444|Allie|Hun|ah1234|HHYZ|1500 def...
Python coding: Write code for each method listed. Input Text File Format: username|Firstname|Lastname|password|accountnumber|balance jh123|Jane|Hudson|45678910|AB45|900 ah444|Allie|Hun|ah1234|HHYZ|1500 def build_dict(): ''' Returns a dictionary created from input file where key is an existing username and value is a list of fistname, lastname, account number and balance. '''    def write_to_file(users): ''' Writes the updated user information to user list file '''
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT