Question: 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

 7. runLengthEncode(dataList) [15 pts] First, you can read about run-length encoding

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

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!