Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can You Help me with the Methods HuffmanTree(int[counts]), void write(String fileName), and Void encode The Huffman Coding Assignment Read this entire document before starting! Begin

Can You Help me with the Methods HuffmanTree(int[counts]), void write(String fileName), and Void encode

image text in transcribed
The Huffman Coding Assignment Read this entire document before starting! Begin by defining a class HuffmanTree.iava that represents a Huffman encoding tree. Define the following methods (more methods will be added later]: Page I of 5' Method De sc riptio n This method will construct the Huffman tree using the supplied array of character frequencies, where COUMS [i] is the number of occurrences of the character with integer (decimal) value 1. For example, counts[32] is the number of spaces. HuffmanTree( int counts ) This method should write your encoding tree void Wtitelring fileName} to the given file in a standard format, using the naming conventions provided later. This method will write a compressed binary void encoae{BiLoutput5tream out String le \"Sing the HUman COdeS generated by \"imam\" ' the Huffman tree. It will write the Huffman code for each character. bit by bit. using BitOu gutStream. The array passed to HuffmanTree's constructor should have exactly 256 elements. but your program should not depend on this. Instead. use the length field of the array to know how many there are. You should use a priority queue to build up the tree as described in the how-to article. Create the 'forest' - add a leaf node for each character that has a frequency greater than 0 (we don't include characters not in the input source in ourtree). These should be added in increasing character (decimal) order {character 0, character 1, and so on). You will need to define a binds class. You should decide what data fields are appropriate to include in the node class. Put this class in a separate file, rather than nested inside the HuffmanTree class, for testing. When building the Huffman tree using a java. util.i1"riorityQueuecE>r you'll be adding values of type Node. This means that your node class shoudl implement the Comparablecb interface, the contract for types that are "order-able". It should use the frequency (weight) of the sub-tree to determine its ordering relative to other sub-trees, with lower frequencies considered "less" than higher frequencies. The provided TreePrinter class will print your Huffman tree in a nice way. when debugging. When overriding the toString method of your node class. recall that only the frequencies matter for interior nodes, while the leaf nodes will store the actual characters. As with the Twenty Questions program. we will use a standard format for outputting the Huffman tree. The output should contain a sequence of line pairs. one for each leaf of the tree. The rst line of each pair should have the integer value of the character stored in that leaf (rather than the corresponding character, which may be something like a newline character and therefore not visible). The second line should have the code {a string of 0's and 1's} for the character with this integer value. Page 2 of 7

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions