Question: Run length encoding is one way to compress a sequence with lots of repeated entries. In run length encoding, repeated entries in a sequence are

 Run length encoding is one way to compress a sequence with

Run length encoding is one way to compress a sequence with lots of repeated entries. In run length encoding, repeated entries in a sequence are replaced by a counter of how many times the repeated. For example, the sequence 1111222 46666611 gets encoded in the following manner 1111222 4 66666 11 14 23 41 65 12 4 times 3 times 1 time 5 times 2 times into the sequence 1423 416512, where the encoded sequence consists of pairs in the form entry counts entry counts entry counts, and so on. Notice that the encoded sequence is shorter than the original sequence as long as there are many repeated entries. Write a program that prompts the user to enter a sequence of integers, separated by a space between each integer, and display the run length encoded output. If the user enters an empty sequence, do not output anything. You may assume that the entered sequence is valid (ie, in the correct format) and contains only integers. Submit your source code in a file named RunLength Encoding.java! Sample input and output (inputs preceded by ): Enter a sequence of integers separated by spaces: > 1111 2 2 2 4 6 6 6 6 6 11 Run length encoder output: 1 4 2 3 4 1 6 5 1 2 Enter a sequence of integers separated by spaces: > 3 3 -5 -5 -5 -5 2 4 4 4 Run length encoder output: 3 2 -5 4 2 1 4 3 2 1 Additional practice problems from the textbook: 5.1, 5.7, 5.10, 5.14,5.19.5.23, 5.26, 3.46 (this is a common interview question!)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!