Write the following in Java: Write a program which implements Huffman Encoding a
ID: 3934570 • Letter: W
Question
Write the following in Java: Write a program which implements Huffman Encoding assuming a code alphabet of Z2, ie, binary codewords. You should start with a class called HuffmanNode.java, which contains the required fields S, P, C, L, as well as a left and a right child HuffmanNode. The algorithm should proceed as follows: First, the user selects a text file, which is read into your program. Each line of the text file will have a symbol, sk S, and a probability, pk P. Each line should be written to a distinct HuffmanNode, (leaving Ck and lk blank for later). The newly semi-filled HuffmanNodes should be added, in increasing order of pk into a HuffmanNode list: an ArrayList of HuffmanNodes. Then the Huffman tree is created by following the Huffman Algorithm. After the tree is created, the tree is traversed recursively in order that the codewords and lengths may be added to the HuffmanNodes. Finally, print your symbols and codes to the screen or to a file for verification. Also, you should traverse your Huffman Tree in order to compute the average codeword length of your new code, (the ACWL(C)).