← IGCSE Computer Science Paper 1

Run-length encoding of a row of coloured pixels

Run-length encoding of a pixel row stores each run of same-coloured pixels as a count then a colour code, in order along the row. E.g. WWWBB becomes 3W2B.

Understanding Run-length encoding of a row of coloured pixels in IGCSE Computer Science Paper 1

What it does: The row is WWWWWBBB. It has two runs, so there are two count and colour code pairs: 5W and 3B. Runs must stay in order along the row. The last B is a separate run after the whites, so it gets its own pair: 1B. Every pixel must be covered. The single blue pixel at the end is a run of length 1, so it needs the pair 1B. Each count says how many pixels are in that run. Add the counts: 5 white + 3 black = 8 pixels. 3W2B and 2B3W add up to the same pixels but are different rows. The order of the pairs rebuilds the row correctly.

Common mistakes: The row should start with three white pixels (W W W), not two. The runs 3 W, 2 K, 4 W and the code 3W2K4W all match the row W W W K K W W W W. The row has four green pixels in a row, so the green run count must be 4, not 3. It should read 'Runs: 2 R, 4 G, 1 B'.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 86–109) and word search (Modules 86–120).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
A row of pixels is WWWBB (W = white, B = black). Which is its run-length encoding?
3W2BW3B2
Matches
WWWWBB encoded as 4B2W
↓
The colour codes are swapped. The four pixels are white, not black, and the two pixels are black, not white.
Applying
Meanings
Term
RLE pixel row
Meaning
Run-length encoding of a pixel row stores each run of same-coloured pixels as a count then a colour code, in order along the row. E.g. WWWBB becomes 3W2B.
Practice
Key: R=Red G=Green B=Blue
Testing
Gaps
RLE: W2B
Check Answer
Spots
1Key: W=white, K=black
2Row: W W K K W W W W

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Lion's Mane Jellyfish' badge — Set Operator, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. A row of pixels is WWWBB (W = white, B = black). Which is its run-length encoding?
A. 3W2B ✓
B. W3B2
Each run is written as the count first, then the colour code. WWW is 3W and BB is 2B, so the row is 3W2B.
2. A black and white row is BBBBWWB. Which encoding is correct?
A. 4B2W1B ✓
B. 5B2W
Runs must stay in order along the row. The last B is a separate run after the whites, so it gets its own pair: 1B.
3. Using the table R = red, G = green, B = blue, how is the row RRRGGB encoded?
A. 3R2G1B ✓
B. 3R2G
Every pixel must be covered. The single blue pixel at the end is a run of length 1, so it needs the pair 1B.
4. How many pixels are in a row encoded as 5W3B?
A. 2 pixels, because there are two pairs
B. 8 pixels, because 5 + 3 = 8 ✓
Each count says how many pixels are in that run. Add the counts: 5 white + 3 black = 8 pixels.
5. Which row does the encoding 2R4G1R decode to?
A. RRRRGGR
B. RRGGGGR ✓
Read each pair as count then colour: 2R is RR, 4G is GGGG, 1R is R. Together that makes RRGGGGR.

Match the Pairs

3W2B → Three white pixels followed by two black pixels along the row (W = white, B = black)
4R1G3R → Four red pixels, one green pixel, then three red pixels (R = red, G = green)
A black and white row with 5 white pixels then 3 black pixels is stored as one count and colour code per run (W = white, B = black) → 5W3B
Using the table R = red, G = green, Y = yellow, the row RRRGGY is encoded run by run, in order → 3R2G1Y
WWWWBB encoded as 4B2W → The colour codes are swapped. The four pixels are white, not black, and the two pixels are black, not white.
RRGGGR encoded as 2R3G → The final run of one red pixel is missing, so the row cannot be rebuilt correctly.

Key Term

RLE pixel row
Run-length encoding of a pixel row stores each run of same-coloured pixels as a count then a colour code, in order along the row. E.g. WWWBB becomes 3W2B.

Fill in the Blanks

1. Row: WWWBB RLE: 3W2B
Hint: Type the count for the first run of white pixels. Count the W pixels before the first B.
2. Table: R=red, G=green, B=blue Row: RRGGGB RLE: 2R3G1B
Hint: Use the colour table. Type the colour code for the run of three pixels.
3. Row 1: BBBW RLE: 3B1W Row 2: WWBB RLE: 2W2B
Hint: Each row is encoded separately. Type the count for the white run at the start of row 2.
4. Row: BBBBWWB RLE: 4B2W1B
Hint: Type the count for the last run, a single black pixel at the end of the row.
5. Row: BBWWWWWB RLE: 2B5W1B
Hint: Runs are written in order along the row. Type the colour code of the final run.

Spot the Error

Question 1
A Key: W=white, K=black
B Row: W W K K W W W W
C Runs: 3 W, 2 K, 4 W
D RLE: 3W2K4W
Line B — The row should start with three white pixels (W W W), not two. The runs 3 W, 2 K, 4 W and the code 3W2K4W all match the row W W W K K W W W W.
Question 2
A Key: R=red, G=green, B=blue
B Row: R R G G G G B
C Runs: 2 R, 3 G, 1 B
D RLE: 2R4G1B
Line C — The row has four green pixels in a row, so the green run count must be 4, not 3. It should read 'Runs: 2 R, 4 G, 1 B'.
Question 3
A Key: Y=yellow, K=black
B Row: Y Y Y K K Y
C Runs: 3 Y, 2 K, 1 Y
D RLE: Y3K2Y1
Line D — Each run is written as the count first, then the colour code. The encoding should be 3Y2K1Y, not colour then count.
Question 4
A Row: R R R G G B
B Key: R=red, G=green, B=blue
C Runs: 4 R, 2 G, 1 B
D RLE: 4R2G1B
Line A — The row only has three red pixels here, but the runs and RLE say 4 R. The row should be R R R R G G B to match 4R2G1B.
Question 5
A Key: W=white, K=black
B Row: K K K W W K
C RLE: 4K2W1K
D Total pixels: 4+2+1 = 7
Line B — The row should start with four black pixels and have seven pixels in total. K K K W W K has only 3 black pixels at the start and 6 pixels, so it does not match 4K2W1K.

Student with a class code? Join your class →