Question: 1 2 . 5 Lab: Huffman Code Huffman codes is a compression scheme for assigning variable - length bit codes to symbols ( letters )

12.5 Lab: Huffman Code
Huffman codes is a compression scheme for assigning variable-length bit codes to symbols(letters) to allow for a minimum cost storage and transmission of messages. The idea is to assign variable-length codes to input characters, with the lengths of the assigned codes are based on the frequencies of corresponding characters.
The variable-length codes assigned to input characters must be Prefix Codes. That means the codes (bit sequences) are assigned in such a way that the code assigned to one character is not the prefix of code assigned to any other character. In this way we ensure that there is no ambiguity when decoding the resulting bitstream.
We would like to implement the encoding and decoding process to allow for the compression of a given text. In addition, we would like to be able to decode a given bitstream with a provided encoding.
Write a program that takes a string as input. It should compute the frequencies and then construct a Huffman Code. For simplicity, use only the upper-case versions of all characters. We would like to have some consistency in selecting symbols to pair.
Select the smaller value first (on the left, implicitly the 0 value). In the case of a tie, select alphabetically with the first letter on the left.
For example, for an input of:
This is his message
The resulting Huffman Code should be:
Huffman Code: ''110'A'0000'E'001'G'0001'H'010'I'111'M'0110'S'10'T'0111
And the encoding of the message should be:
Encoded string is: 01110101111011011110110010111101100110001101000000001001
c++ please

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!