Sign in

Intro to Computer Science / Unit 2: Binary and Data Representation

2.5 Data Compression

3 practice questionsNot yet reviewed

Notes

Compression makes files smaller so they use less storage and are faster to send.

  • Lossless compression keeps all the original data, so the file can be restored exactly (ZIP files, PNG images).
  • Lossy compression throws away some data that people may not notice, to make the file much smaller (JPEG images, MP3 sound). The original cannot be fully restored.
  • Run-length encoding replaces repeats with a count: "AAAABBB" becomes "4A3B".
  • Example: "WWWWWWWWWWBB" (10 W and 2 B) becomes "10W2B".
  • Use lossless for text and programs, where every bit matters.

Practice

What is "AAABBBBCC" after run-length encoding?
Which kind of compression can be reversed to get the exact original file?
A programmer wants to compress a text document of source code before emailing it. Which type should be used and why?

Ready for more? Take the Unit 2 test.