Question
Data compression In this assignment, you will implement the LZW compression algorithm described in section 5.5. In a program called Compress, write a method compress(String
Data compression
In this assignment, you will implement the LZW compression algorithm described in section 5.5. In a program called Compress, write a method compress(String s) that takes a string as a parameter and that returns an array list of integers. The array list contains the list of codes generated by the LZW compression algorithm. Besides the array list, you will also need a symbol table to store strings and their codes, which are integers. As in the example given in class, initialy fill the symbol table with single-character strings of the characters from ASCII code 0x00 to 0x7f. Use a for-loop where the index variable is of type Character. Its ASCII value can be found using the charValue() method in the Character class.
Once the symbol table is initialized, scan the string in the way described in class and in the textbook for LZW algorithm, adding codes to the array list. When your code is run through the string, add the value 0x80 to the end of the array list and return it.
In your main method, call the compress method. Print every entry in the array list using a statement such as:
StdOut.printf("%x ", code);
Test your program on the string given in class (I think it was "ABRACADABRABRABRA"). Your output should match the output given.
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