Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Run-length encoding is a simple compression scheme best used when a data-set consists primarily of numerous, long runs of repeated characters. For example, AAAAAAAAAA is

Run-length encoding is a simple compression scheme best used when a data-set consists primarily of numerous, long runs of repeated characters. For example, AAAAAAAAAA is a run of 10 As. We could encode this run using a notation like *A10, where the * is a special flag character that indicates a run, A is the symbol in the run, and 10 is the length of the run. As another example, the string would be encoded

KKKKKKKKKKKKKBCCDDDDDDDDDDDDDDDKKKKKMNUUUGGGGG $K13BCC$D15$K5MNUUU$G5

assuming in this case that $ is the flag character. For the sake of this problem we will assume that the input strings to be encoded contain only uppercase letters from the Latin alphabet and that no run is longer than 99 characters long. Note that single letters, runs of two letters, and runs of three letters are not encoded, as doing so does not save memory or actually compress the data. Do you see why that is the case?

Write a method

public static String encode(String message, char delimiter) 

that takes a string consisting of uppercase letters only and returns the run-length encoded input string. Below are sample runs of the program showing how input and output must be formatted by your program.

Example 1:

encode(XYZAAAAAAGGTCCCCCCTTTAAAAAAAAAAAAAAKK, *) Return: XYZ*A6GGT*C6TTT*A14KK

,

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

More Books

Students also viewed these Databases questions