Question: Write this in C# language. Part C: Huffman Codes ( 4 0 marks ) Background In 1 9 5 2 , David Huffman published a

Write this in C# language.
Part C: Huffman Codes (40 marks)
Background
In 1952, David Huffman published a paper called "A Method for the Construction of Minimum-Redundancy Codes". It was a seminal paper. Given a text of characters where each character occurs with a frequency greater than 0, Huffman found a way to encode each character as a unique sequence of 0's and 1's such that the overall length (number of bits) of the encoded text was minimized.
Huffman recognized that characters with a greater frequency should have shorter codes than those with a lower frequency. Therefore, to disambiguate two codes, no shorter code of 0's and 1's can serve as the prefix (beginning) of a longer code. For example, if letter 'a' has a code of 010, no other character can have a code that begins with 010.
To find these codes, a Huffman tree is constructed. The Huffman tree is a binary tree where the left edge of each node is associated with the number 0 and the right edge is associated with the number 1. All characters are stored as leaf nodes and the code associated with each character is the sequence of 0's and 1's along the path from the root to the character.
Requirements
As a start, read up on Huffman Codes in your text. Then, implement the Huffman class which tackles each of the following tasks.
Task 1: Determine the Character Frequencies
Determine the frequency of each character in the given text and store it in an array using the character itself to map to an index. Assume all printable ASCII characters, codes 32 to 126, may be used as part of the text (see AnalyzeText).
Task 2: Build the Huffman Tree
Using a priority queue of binary trees, a Huffman tree is constructed for the given text. Initially, the priority queue is populated with as many as 95 individual nodes (binary trees of size 1) where each node stores a character and its frequency. The priority queue is ordered by frequency where a binary tree with a lower total frequency has a higher priority than one with a higher total frequency (see Build).
Task 3: Create the Codes
The final Huffman tree is then traversed in a prefix manner such that the code for each character is stored as a string of 0 s and 1 s and placed in an instance of the C# Dictionary class using its associated character as the key (see CreateCodes) and the string as the value.
Task 4: Encode
Using the dictionary of codes, a given text is converted into a string of Os and 1s (see Encode).
Task 5: Decode
Using the Huffman tree, a given string of 0 s and 1 s to converted back into the original text (see Decode).
To help implement your program, consider the following skeleton of code.Page 5 of 7
To help implement your program, consider the following skeleton of code.Page 5 of 7
Write this in C# language. Part C: Huffman Codes

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!