Question
Task 1: Determine the Character Frequencies Determine the frequency of each character in the given text and store it in an array. For simplicity, only
Task 1: Determine the Character Frequencies Determine the frequency of each character in the given text and store it in an array. For simplicity, only lowercase letters from a to z, upper-case letters from A to Z, and the blank (space) are admissible as characters (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 53 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 0s and 1s, and placed in an instance of the C# Dictionary class using its associated character as the key (see CreateCodes). Task 4: Encode Using the dictionary of codes, a given text is converted into a string of 0s and 1s (see Encode). Task 5: Decode Using the Huffman tree, a given string of 0s and 1s to converted back into the original text (see Decode). To help implement your program, consider the following skeleton of code.
class Node : IComparable { public char Character { get; set; } public int Frequency { get; set; } public Node Left { get; set; } public Node Right { get; set; } public Node (char character, int frequency, Node left, Node right) { } // 5 marks public int CompareTo ( Object obj ) { } } class Huffman { private Node HT; // Huffman tree to create codes and decode text private Dictionary
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started