Question: I need help with programming in Java. Below is the question I have to answer (including both parts A and B). I am having a

I need help with programming in Java. Below is the question I have to answer (including both parts A and B). I am having a lot of trouble with the coding but I think I understand the concept. Underneath the question is the work I have done on the problem and my code so far. If anything is wrong or if you need to change anything in my code please feel free to do so.

Letter C E I R S T X
Frequency 12 8 18 10 9 5 2

Q1) Write a program in Java to construct a Huffman tree for encoding with the above data. Your output have to generate an optimal binary prefix code for each letter. Please Include the image of your output.

A) Decode each bit string using the Huffman code.

011000101010100 - (I determined it should be ECTTC)

1000100001010100 - (I determined it should be ICICTX)

111001001111110 - (I determined it should be RCIERI)

1000010011100 - (I determined it should be ICXRC)

B) Encode each word using the Huffman code in 1.

RISE - (I determined it should be 11110110011)

EXIT - (I determined it should be 0110100100101)

TEXT - (I determined it should be 010101101000101)

EXERCISE - (I determined it should be 01101000111110010110011)

MY WORK SO FAR:

I need help with programming in Java. Below is the question I

MY CODE SO FAR:

import java.util.*; abstract class HuffmanTree implements Comparable { public final int frequency; // the frequency of this tree public HuffmanTree(int freq) { frequency = freq; } // compares on the frequency public int compareTo(HuffmanTree tree) { return frequency - tree.frequency; } } class HuffmanLeaf extends HuffmanTree { public final char value; // the character this leaf represents public HuffmanLeaf(int freq, char val) { super(freq); value = val; } } class HuffmanNode extends HuffmanTree { public final HuffmanTree left, right; // subtrees public HuffmanNode(HuffmanTree l, HuffmanTree r) { super(l.frequency + r.frequency); left = l; right = r; } }

2 x 5 T 18 l I IS II IS -p 15 2 x 5; T 37* 27 37 I 2? 9: S 10: R a: s to: R 21 X ST E -b 011 37 27 12 C IS:* I 19 ais lo R 2 x 5 T

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 Databases Questions!