Back to the topic

The mark scheme starts on a new page, so you can print pages one and two for a student and keep the last page yourself. Everything prints in black on white whichever theme you are using.

AQA GCSE CS · 3.3.7

Data Compression, Huffman and RLE

Section A: 10 multiple choice questions, 10 marks. Section B: 5 written questions, 18 marks. Total 28 marks.

Name

Class

Date

Mark  / 28

Section A

Circle the letter of the correct answer. One mark each.

  1. 1What is the defining feature of lossy compression?1
    1. AIt uses a Huffman tree
    2. BData is permanently removed and the original cannot be recovered exactly
    3. CIt only works on text files
    4. DThe file gets smaller with no change to the data
  2. 2Why must a text document be compressed losslessly?1
    1. AText cannot be compressed
    2. BText files are already small
    3. CLossy compression only works on binary files
    4. DEvery character carries meaning, so removing any of them changes the content
  3. 3How would W W W B B B B W be written using run length encoding?1
    1. A3W 4B
    2. B3W 4B 1W
    3. C8 values unchanged
    4. DW3 B4 W1 with no counts
  4. 4When does run length encoding make a file larger?1
    1. AWhen the data is a photograph in colour
    2. BWhen the runs are longer than ten
    3. CWhen the data contains few or no repeated runs
    4. DWhen the file is already compressed with Huffman
  5. 5In Huffman coding, which characters get the shortest codes?1
    1. AThe most frequent ones
    2. BThe least frequent ones
    3. CThe ones earliest in the alphabet
    4. DAll characters get equal length codes
  6. 6When building a Huffman tree, which two nodes are combined at each step?1
    1. AThe two with the lowest frequencies
    2. BThe two with the highest frequencies
    3. CThe first two alphabetically
    4. DAny two that are adjacent
  7. 7The word MISSISSIPPI is 11 characters. In 7 bit ASCII, how many bits does it take?1
    1. A11
    2. B44
    3. C77
    4. D88
  8. 8Why can a Huffman coded stream be decoded without separators between characters?1
    1. AThe codes are stored alphabetically
    2. BNo character's code is the beginning of another character's code
    3. CA separator bit is added automatically
    4. DEvery code is the same length
  9. 9Which pair of file types are most appropriately compressed lossily?1
    1. AA program and a photograph
    2. BA database and a text file
    3. CA spreadsheet and a program
    4. DA photograph and a music track
  10. 10A file compresses from 2000 bits to 750 bits. What is the percentage saving?1
    1. A62.5 per cent
    2. B75 per cent
    3. C26.6 per cent
    4. D37.5 per cent

Section B

Answer in the space provided. The number of marks tells you how many separate points to make.

  1. 1StateState two reasons why a file might be compressed before being sent over the internet.2
  2. 2ExplainExplain the difference between lossy and lossless compression, and give one appropriate use of each.4
  3. 3ShowA row of an image contains the pixels W W W W B B W W W W W W. Show how this row would be stored using run length encoding, and state one reason why RLE would be a poor choice for a photograph.4
  4. 4DescribeThe word ABRACADABRA is to be compressed using Huffman coding. Describe how the Huffman tree would be constructed, and explain how the code for a character is obtained from it.5
  5. 5CalculateA message of 40 characters is stored in 7 bit ASCII. After Huffman coding it needs 148 bits. Calculate the number of bits saved and the saving as a percentage of the original.3

Mark scheme

Section A

1B2D3B4C5A6A7C8B9D10A

Section B

1 State two reasons why a file might be compressed before being sent over the internet. 2

One mark for each of the following, to a maximum of 2.

  • It takes less time to transmit
  • It uses less bandwidth, or takes less storage space at the other end

Model answer. A compressed file contains fewer bits, so it takes less time to send, which matters particularly on a slow connection. It also uses less bandwidth, which reduces congestion on the network and lowers the cost for anybody paying for the data they use.

2 Explain the difference between lossy and lossless compression, and give one appropriate use of each. 4

One mark for each of the following, to a maximum of 4.

  • Lossy compression permanently removes data, so the original cannot be recovered
  • Gives a suitable lossy use such as photographs, music or video
  • Lossless compression stores the same data more efficiently, so the original is recovered exactly
  • Gives a suitable lossless use such as text, program code or a spreadsheet

Model answer. Lossy compression achieves a large reduction by permanently discarding data judged to be less important, which means the original file cannot be reconstructed exactly. It is appropriate for photographs and music, where human perception does not register the detail that is removed, which is why JPEG and MP3 are used. Lossless compression instead finds a more efficient way of storing exactly the same information, so the original is recovered perfectly, at the cost of a more modest reduction in size. It is essential for text documents, program code and spreadsheets, where every character carries meaning and discarding any of it would corrupt the file.

3 A row of an image contains the pixels W W W W B B W W W W W W. Show how this row would be stored using run length encoding, and state one reason why RLE would be a poor choice for a photograph. 4

One mark for each of the following, to a maximum of 4.

  • Identifies the runs correctly as four W, two B, six W
  • Writes them as value and count pairs
  • A photograph has very few long runs of identical pixels
  • So RLE would give little saving and could make the file larger

Model answer. The row contains four W, then two B, then six W, so under run length encoding it is stored as the pairs 4W, 2B, 6W. That is three pairs, six values in total, in place of the original twelve, and nothing has been lost. Run length encoding would be a poor choice for a photograph because photographs contain gradients and noise rather than blocks of identical colour, so almost every run has a length of one. Each single pixel would then be stored as a value and a count, which is two values where one was needed, and the compressed file would be larger than the original.

4 The word ABRACADABRA is to be compressed using Huffman coding. Describe how the Huffman tree would be constructed, and explain how the code for a character is obtained from it. 5

One mark for each of the following, to a maximum of 5.

  • Counts the frequency of each character
  • Creates a node for each character with its frequency
  • Repeatedly combines the two nodes with the lowest frequencies under a new parent
  • Continues until one root node remains, and labels branches 0 and 1
  • A character's code is read by following the branch labels from the root down to that character

Model answer. First count how often each character occurs: A appears five times, B twice, R twice, C once and D once. Each character becomes a node carrying its frequency. The two nodes with the lowest frequencies, C and D, are then joined under a new parent node whose frequency is their total of two. That process repeats, always taking the two lowest frequencies still available, until a single root node remains holding the total of eleven. Every left branch is then labelled 0 and every right branch 1. To obtain the code for a character you start at the root and follow the branches down to that character's leaf, writing down each label as you pass it. Because A is the most frequent it ends up nearest the root and gets the shortest code, while C and D are deepest and get the longest, which is what makes the total number of bits smaller than fixed length coding would need.

5 A message of 40 characters is stored in 7 bit ASCII. After Huffman coding it needs 148 bits. Calculate the number of bits saved and the saving as a percentage of the original. 3

One mark for each of the following, to a maximum of 3.

  • Calculates the ASCII size as 280 bits
  • Calculates the saving as 132 bits
  • Gives approximately 47 per cent

Model answer. In 7 bit ASCII the message takes 40 multiplied by 7, which is 280 bits. Huffman coding needs 148 bits, so the saving is 280 minus 148, which is 132 bits. As a percentage of the original that is 132 divided by 280, which is 0.4714, or approximately 47 per cent.