Question: Huffman codes is a compression scheme for assigning variable - length bit codes to symbols ( letters ) to allow for a minimum cost storage
Huffman codes is a compression scheme for assigning variablelength bit codes to symbolsletters to allow for a minimum cost storage and transmission of messages. The idea is to assign variablelength codes to input characters, with the lengths of the assigned codes are based on the frequencies of corresponding characters.
The variablelength 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 uppercase versions of all characters.
Note: We will construct the code by pairing the lowest frequency nodes at each step. The lower frequency node will be assigned the value encoding. In the case of a tie, the first letter alphabetically will be assigned the value
For example, for an input of:
This is his message
The resulting Huffman Code should be:
Huffman Code:
A
E
G
H
I
M
S
T
And the encoding of the message should be:
Encoded string is:
provide the code according to these instructions within main.cpp
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
