Computers and Technology

Run-length encoding (35 points). Data compression is used behind the scenes in computer systems quite often, computer files and other kinds of data can be compressed to a smaller size for easy storage or transportation. Later, they are decompressed and used in their original form. One basic idea is to find parts of the data that are identical to each other and use some kind of trick to describe that more efficiently.

Run-length encoding (RLE) encodes a run of repetitions with the length of that run. RLE is a simple compression algorithm (an algorithm which takes a block of data and reduces its size, producing a block that contains the same information in less space). It works by replacing repetitive sequences of identical data items with short tokens that represent entire sequences. Applying RLE to a string involves finding sequences in the string where the same character repeats. Replace each such sequence by a token consisting of:

the number of characters in the sequence
the repeating character
If a character does not repeat, it appears as a single character in the compressed string with no number preceding it.

For example, consider the following string:


After applying the RLE algorithm, this string is converted into:

q9w5e2rt5y4qw2Er3T
In the compressed string, "9w" represents a sequence of 9 consecutive lowercase "w" characters. "5e" represents 5 consecutive lowercase "e" characters, etc.

Write a RLE library by implementing the following API:

public class RunLengthEncoding {

// Encodes the original string by finding sequences in the string
// where the same character repeats.
// Replace each such sequence by a token consisting of: the number
// of characters in the sequence followed by the repeating character.
// Write an iterative encode method.
// Returns the encoded string.
public static String encode (String original)

// Decodes the original string encoded with the encode method.
// Returns the decoded string.
// YOUR decode METHOD MUST BE RECURSIVE.
// Do not use while, do/while, or for loops.
public static String decode (String original)

// Tests each of the API methods by directly calling them.
public static void main (String[] args)
}
For decode, you may assume that the character counts will be single-digit numbers (a character will not repeat more than 9 times consecutively). Hint #1: remember that characters are represented by numeric codes. You can decrement a character variable as follows:

char c = '7';
c--; // c will now hold the character '6'
Hint #2: You can check if a character is a digit by using the isDigit() method from the Character class as follows:

char c = '7';
Character. isDigit(c); // returns true
Hint #3: You probably will not need to use this hint for this problem. However, a fast way to convert a digit character into the numeric value of the digit is to subtract the character code for the digit zero:

char c = '7'; // this has the character code 55, not 7
int x = c - '0'; // this produces the number 7

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 23:00, xxbriannahollandxx
In a file-oriented information system, a work file stores relatively permanent data about an entity is created and saved for backup and recovery purposes stores records that contain day-to-day business and operational data is a temporary file created by an information system for a single task
Answers: 1
image
Computers and Technology, 22.06.2019 05:10, ahoney2233
Suppose we have a byte addressable computer that has a 32-byte cache with 8 bytes per block. the memory address is 8 bits long. the system accesses memory addresses (in hex) in this exact order: 6e, b9, 17, e0, 4e, 4f, 50, 91, a8, ab, ad, 93, and 94. (a) assuming the cache is direct mapped, what memory addresses will be in cache block 2 after the last address has been accessed? (b) assuming the cache is direct mapped, what is the hit ratio for the entire memory reference sequence given, assuming the cache is initially empty? (c) assuming the cache is 2-way set associative with a lru replacement policy, what is the hit ratio?
Answers: 3
image
Computers and Technology, 23.06.2019 06:30, Knownothing
When early motion pictures played in movie theaters, they were often accompanied by live organ or piano music. which of the following are the most likely reasons that this happened? (select all that apply). the music was provided to distract audience members from the loud sounds made when filmstrips were changed. the music accompanied the movies because the movies were silent and audiences were used to hearing music during plays in theaters. the music usually was played before, and sometimes after the movie, as an alternative form of entertainment. the music viewers to interpret the dramatic action in the films.
Answers: 2
image
Computers and Technology, 23.06.2019 12:10, jefersina16
2. fabulously fit offers memberships for$35 per month plus a $50 enrollmentfee. the fitness studio offersmemberships for $40 per month plus a$35 enrollment fee. in how many monthswill the fitness clubs cost the same? what will the cost be?
Answers: 1
Do you know the correct answer?
Run-length encoding (35 points). Data compression is used behind the scenes in computer systems quit...

Questions in other subjects: