When run-length encoding saves or costs bytes

A text compressor uses run-length encoding: it replaces consecutive copies of the same character with records containing a character and its repetition count. Each record occupies exactly two bytes: one byte for the character and one byte for a count from 1 through 255.


The compressor uses the longest possible record at each position. More than 255 consecutive copies require additional records. The original text uses one byte per character, and neither format has a header or other overhead.


Complete the table with exact integers. Calculate signed byte savings as original bytes minus compressed bytes; a negative saving means the compressed version is larger.

Source textRecordsCompressed size (bytes)Signed savings (bytes)
A repeated 18 times
AB repeated 9 times
A repeated 300 times

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Text Encoding and Compression Techniques Questions: