Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

7. runLengthEncode(dataList) [15 pts] First, you can read about run-length encoding and compression here. Then, write the function runLengthEncode(dataList) that takes a list of numbers

image text in transcribed

7. runLengthEncode(dataList) [15 pts] First, you can read about run-length encoding and compression here. Then, write the function runLengthEncode(dataList) that takes a list of numbers and returns a list of numbers that results from "reading off" the initial list, using tuples for each (count, value) pair. This is similar to the look-and-say method. For example: runLengthEncode ([])==[] runLengthEncode ([1,1,1])==[(3,1)] runLengthEncode ([1,2,7])==[(1,1),(1,2),(1,7)] runLengthEncode ([3,3,8,1,10,10])==[(2,3),(1,8),(3,1)] runLengthEncode ([3,3,8,3,3,3,3])==[(2,3),(1,8),(4,3)] Understanding the following is not necessary for completing this problem. However, if you are curious, run-length encoding on files does not always result in smaller file sizes, and works best for data with long runs of repeated values (like simple black-and-white images, for example). Since each tuple in a run-length-encoded list contains two values, we can approximate the compression ratio for a paritcular list like so: def compressionRatio(uncompressedList): rle = runLengthEncode(uncompressedList) return len (uncompressedList) /( len ( rle )2) A higher compression ratio is preferable. If the compression rate is less than 1 , however, the run-length-encoded list contains more values than the original list. For example: print(compressionRatio ([3,1,4,1,5,9,2])) \# Prints .5 ! Lastly, on the subject of compression, you may find this paper interesting! The segmentation mask (right) is stored as 640,000 integers with values 0 to 6 , representing the label for each pixel. Using our runLengthEncode function, we can compress this down to only 26,098 integers, a compression ratio of 24.5:1,0.04078 times the original size

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions

Question

4. Identify cultural variations in communication style.

Answered: 1 week ago