(Java)Run length encoding is a simple form of data compression. It replaces long sequences of a repeated...

80.2K

Verified Solution

Question

Programming

(Java)Run lengthencoding is a simple form of data compression. It replaces longsequences of a repeated value with one occurrence of the value anda count of how many times to repeat it. This works reasonably wellwhen there are lots of long repeats such as in black and whiteimages. To avoid having to represent non-repeated runs with a countof 1 and the value, a special value is often used to indicate a runand everything else is just treated as a simple value. For thisexercise you will decompress one line of input at at time assumingthe line was compressed according to the following:

The newline charactersare passed through uncompressed even when there are repeated blanklines. When a run of n>=3 repeated characters, c, is detectedwhere c is NOT a digit, the run will be replaced with #nc. When arun of n>=3 repeated characters, c, is detected where c IS adigit, the run will be replaced with #n#c. The extra # is needed toavoid confusing the repeated digit c with the last digit of the runcount. All other characters (i.e. runs of just 1 or 2 characters)are passed through unmodified. Assume the uncompressed input doesnot contain the symbol '#'. This assumption can be eliminated. Youmight think about how you would do it.

Some examples:

abc decompresses toabc

#3ab#4c decompressesto aaabcccc

abc12#14#3decompresses to abc1233333333333333

Your decoder canassume the input was properly compressed, i.e. no need for errorchecking. Your program must include a public static methoddecompress() that takes one parameter, a String, that is the lineto be decompressed. The method returns the decompressed String.Write Decoder.java to answer this question.

Answer & Explanation Solved by verified expert
3.7 Ratings (345 Votes)
The length encoding is a simple form of data compression It replaces long sequences of a repeated value with one occurrence of the value and a count of how many times to repeat it This works reasonably well when there are lots of long repeats such as in black and white images To avoid having to represent nonrepeated runs with a count of 1 and the value a special value is often used to indicate a run and everything else is just treated as a simple value For this exercise you will decompress one line of input at at time assuming the line was compressed according to the blow giving code and the data package com import    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students