Question bank › GCSE › GCSE Computer Science › Fundamentals of data representation

Data compression: Huffman coding & RLE

10 questions47 marksabout 55 min

Answer on paper first, then reveal the mark scheme one mark at a time.

1Grade 8–97 marks

(a) Run length encoding (RLE) represents data as frequency/data pairs. Give the RLE of this bit pattern as frequency/data pairs. [2]

0000000111110000000011

(b) The Huffman tree shown was built for the text ABRACADABRA.

(i) State the Huffman code for the character R. [1]

(ii) Calculate the number of bits needed to store ABRACADABRA using this Huffman code. [2]

(iii) Calculate how many bits are saved compared with storing the text using 7-bit ASCII. [2]

11642A (5)B (2)R (2)C (1)D (1)01010101
2Grade 1–34 marks

Files are often compressed before they are stored or sent across a network.

(a) State what is meant by data compression. [1]

(b) Give two reasons why a file might be compressed. [2]

(c) Name one method of compression other than run length encoding (RLE). [1]

3Grade 1–33 marks

Run length encoding (RLE) represents data as frequency/data pairs.

(a) Write the RLE of the following sequence of characters as frequency/data pairs. [2]

WWWWBBBWWWWWWBW

(b) State the number of frequency/data pairs in your answer to (a). [1]

Stuck on Data compression: Huffman coding & RLE?

Get it sorted in a free 30-minute session

We work through your weakest questions on this topic on Zoom. I reply the same day.

4Grade 4–54 marks

A 16-bit pattern has been compressed using run length encoding (RLE). The frequency/data pairs are:

4 1   2 0   6 1   1 0   3 1

(a) Write out the original 16-bit pattern. [2]

(b) RLE would not be a good way to compress the bit pattern 0101010101010101. Explain why. [2]

5Grade 4–55 marks

The Huffman tree shown was built for the text MISSISSIPPI. Left branches are labelled 0 and right branches are labelled 1.

(a) State the Huffman code for the character P. [1]

(b) Write the Huffman code for the characters SIP. [1]

(c) Calculate the number of bits needed to store the whole text MISSISSIPPI using this Huffman code. Show your working. [2]

(d) State the number of bits needed to store the text using 7-bit ASCII. [1]

0130170111S (4)I (4)P (2)M (1)
6Grade 6–74 marks

A Huffman tree has been built for a message containing only the characters E, T, A and S. Left branches are labelled 0 and right branches are labelled 1.

(a) Use the tree to decode the following Huffman-coded data. [2]

0010100111

(b) Write the Huffman code for the word SEAT. [1]

(c) Explain why the decoded message is not ambiguous even though the codes have different lengths and there are no separators between them. [1]

0140170112T (3)A (2)S (2)E (5)
7Grade 6–75 marks

A student compressed three different files using run length encoding (RLE) and Huffman coding. The table shows the results.

FileDescriptionUncompressed sizeSize after RLESize after Huffman coding
LogoBitmap image with large areas of one colour480 kB60 kB300 kB
PhotoBitmap photograph2400 kB2550 kB2100 kB
EssayText document120 kB118 kB72 kB

(a) Calculate the percentage reduction in file size when the logo is compressed using RLE. [2]

(b) Explain why the photo became larger when RLE was used. [2]

(c) State which method of compression the student should use for the essay. [1]

8Grade 6–76 marks

The diagram shows two rows of pixels from a black-and-white bitmap image. Each row is 16 pixels wide. A black pixel is stored as 1 and a white pixel as 0.

Each row is compressed using run length encoding (RLE). Each frequency/data pair is stored using 4 bits for the frequency followed by 1 bit for the colour.

(a) Write the RLE of Row 1 as frequency/data pairs. [2]

(b) Calculate the number of bits needed to store Row 1 using RLE. [2]

(c) Using a calculation, show that RLE would increase the number of bits needed to store Row 2. [2]

Row 1Row 2
9Grade 8–95 marks

The Huffman tree shown was built for the 16-character text A BANANA BANDANA. The leaf labelled space represents the space character. Left branches are labelled 0 and right branches are labelled 1.

(a) State the Huffman codes for B and D. [1]

(b) Calculate the number of bits needed to store the whole text using this Huffman code. Show your working. [2]

(c) A student suggests that, because the text uses only five different characters, a fixed-length code of 3 bits per character could be used instead. Calculate the number of bits this would need and explain why Huffman coding needs fewer bits. [2]

0130150190116A (7)N (4)space (2)B (2)D (1)
10Grade 8–94 marks

Two 8-character texts are to be compressed using Huffman coding.

Text 1: AAAAAABC

Text 2: ABCDEFGH

(a) Explain which text Huffman coding will compress more effectively. [2]

(b) Explain why the Huffman tree (or the table of codes) must be stored or sent along with the compressed data. [1]

(c) Explain why Huffman coding is a lossless method of compression. [1]

Stuck on this topic?

Book a free 30-minute session on WhatsApp and we'll find exactly which step is costing you the marks. Or build a timed paper on it.

Free 30-minute session