Recovering a text compressor's header cost

A sensor produces a 40-character text message containing 20 occurrences of A, 10 of B, 6 of C and 4 of D. Its original representation uses one byte per character and has no header.


A compressor uses the following prefix code, in which no character's complete bit pattern is the beginning of another character's bit pattern.


Character

Compressed bit pattern

A

0

B

10

C

110

D

111


The compressed file contains a fixed 320-bit header followed by the payload. The header includes the decoding table and the meaningful payload length. The complete file is padded with zero bits to the next whole byte only when necessary. One byte contains eight bits, and there is no other overhead.


Find the payload length for one message in bits and the complete compressed file size for one message in bytes. Then find the smallest positive integer number of identical message copies that makes a single compressed file strictly smaller than the corresponding original text. When copies share a file, there is one header and padding only at the end; the compressor applies the same code separately to every character without any additional compression.


Give all three answers as exact integers.

Your answers

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: