Practice Data Compression in CS Thinking
Use these practice problems to test your method after reviewing the concept explanation and worked examples.
Quick Recap
Data compression is the process of reducing the number of bits needed to store or transmit information. Some compression is lossless, meaning the original data can be recovered exactly, while some is lossy, meaning some detail is discarded to save more space.
Compression is packing information more tightly so files take less space or move faster across a network.
Showing a random 20 of 50 problems.
Example 1
mediumRLE on `AAABBBBCC` produces what string, and is it shorter than the original?
Example 2
mediumRLE encodes `AAAAAAABBBBC` (7 A's, 4 B's, 1 C). Give the encoded form and original/compressed character counts.
Example 3
mediumYou must transmit medical X-ray images. Which compression type is appropriate and why?
Example 4
mediumA photo is JPEG-compressed, then that JPEG is re-saved as JPEG several more times. What happens to quality and why?
Example 5
hardBy the pigeonhole principle, no lossless algorithm can compress EVERY -bit file to fewer than bits. Why?
Example 6
mediumRLE on `ABABAB` produces `1A1B1A1B1A1B`. Why did compression FAIL here?
Example 7
mediumA backup grows from GB to GB, but the compressed size only grows from GB to GB. Which compression ratio improved, original compressed?
Example 8
hardA K frame raw is MB. A codec produces MB per frame at fps. Compute the compression ratio per frame.
Example 9
hardHuffman codes for symbols with probabilities have lengths . Compute the expected bits per symbol.
Example 10
mediumA 100 MB dataset must transfer over a link in under 10 seconds, and the link does 5 MB/s. What minimum compression ratio is required?
Example 11
easyA song file is 8 MB and compresses to 2 MB. What is the compression ratio?
Example 12
hardA MB video must stream in real time over a MB/s connection for s of content. What compression ratio minimum is required?
Example 13
easyIf a file does not compress at all (ratio 1:1), what does that suggest about its data?
Example 14
easyApply RLE to the string `BBBBBB` (6 B's). Give the compressed form.
Example 15
hardA 8-bit grayscale image compresses to KB. Compute the compression ratio (raw bytes compressed bytes).
Example 16
mediumA backup is 80 GB raw and compresses at 5:1. What is the compressed size, and how much space is saved?
Example 17
challengeYou receive a MB file in seconds on a MB/s link. Explain how this is possible.
Example 18
easyTrue or false: PNG is a LOSSLESS image format.
Example 19
easyA file shrinks from 200 KB to 50 KB. What is the compression ratio?
Example 20
easyApply RLE to `CCCCDDDD`. What is the output?