Starting from:
$30

$24

CSC3100 Assignment 2 Solved

Functional Requirement:

This assignment implements the Huffman tree (https://en.wikipedia.org/wiki/Huffman_coding), which is a powerful algorithm widely in data compression. Two programs are required.
    1. HuffmanCompression.java compresses a given text file (encoded with ASCII code) using Huffman tree method with the following command:

java HuffmanCompression input.txt dictionary.txt compressed.txt


An example of input file follows:


input.txt (note: there is a linefeed symbol at the end of the following sentence)

SUSIE SAYS IT IS EASY


After constructing a Huffman tree, one file of code dictionary will be output:


dictionary.txt

10:01110

32:00

65:010

69:1111

73:110

83:11

84:0110

85:01111

89:1110


The dictionary shows that the space character will encoded as “01110” (note that 10 is the ASCII code of the linefeed character. 32 is the ASCII code of the space character…)

The other output will be the compressed text:


compressed.txt

11011111111011110011010111011001100110001101100111101011111001110


The file gives the compressed text of the input.txt based on the dictionary shown above.

    2. HuffmanDecompression.java decompresses a compressed text based on the Huffman code dictionary with the following command:

java HuffmanDecompression compressed.txt dictionary.txt output.txt


The compressed.txt and dictionary.txt are input files obtained from the compression process. The output file (“output.txt”) should have the same contents as “input.txt” used in the compression process.


Program Template:

Each submission is expected to strictly follow the template to implement the required function.

    1. Modify getHuffmanCode() and getCompressedCode() in HuffmanCompression.java to implement the required compression function.

    2. Modify main() in HuffmanDecompression.java to implement the required decompression function.

Appendix

    1. HuffmanCompression.java

    2. HuffmanDecompression.java

    3. input.txt

    4. dictionary.txt

    5. compressed.txt

    6. output.txt

More products