Question
We are implementing a Huffman tree to encode and decode strings to and from variable-width encodings in JAVA . I have the code done, but
We are implementing a Huffman tree to encode and decode strings to and from variable-width encodings in JAVA. I have the code done, but get the wrong output for the second test and I think it is because I am not meeting this constraint. We are supposed to meet this constraint: "When you initially add characters to your priority queue, break frequency ties alphabetically. Thereafter, when adding a new node to the priority queue, it should come after all nodes already on the queue with the same frequency."
Can you edit my code to get the correct output for the second test case? The test case is given below, along with the expected output. You can find my code here: pastebin.com/aXTRKS2m
------------------------------------------------------------------------------------------
Sample Input 0
emma dora ruth ziegellaub eichler 0111010100101011110011110000101101111001001001010001011101011011000000011100110111110
Sample Output 0
110011101111110100101011011100111101000010110111100100100101000101110101101100000001110011011111010011001011111110100000110001 miriam ruth ziegellaub
Sample Input 1
i am writing a long meaningless sentence about absolutely nothing. hallelujah! 10101001101111110000001100011001111011111111011011
Sample Output 1
10101000001101111000110010110001010101110100010100100000100111101010010100100110111111000000110100010100111111100111011110001111110001101111100011100101110100000110011010111010101110000011001101110101111111010101111101111011010100001010110111100010100010100011011100110000001111111111101111110101101101000110001101100 i mean well.Implement a Huffman tree to encode and decode strings to and from variable-width encodings. Input Format The input will consist of two lines. The first line will be the string to derive your codes from and encode. Build your Huffman tree from this string. The second line will consist of a test string of Os and 1s to decode. The input will terminate with a blank line. For example, emma dora ruth ziegellaub eichler Constraints When you initially add characters to your priority queue, break frequency ties alphabetically. Thereafter, when adding a new node to the priority queue, it should come after all nodes already on the queue with the same frequency Output Format The output will consist of two lines. The first line will be the encoding of the first input string according to your tree. The second line will be the decoding of the second input string according to your tree. For example 10111010110001101011110 miriam ruth ziegellaub
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