Encode repeated data with run-length encoding
Apply run-length encoding to repeated symbols and explain when the lossless method saves space.
Exam scope and assessment notes
This sequence follows Cambridge IGCSE Computer Science 0984, 2026–2028 syllabus Version 4. It covers subject content sections 1.1–1.3 only. The separately published 2029–2031 syllabus is not mapped here. Practice is original, self-checked and does not award an official Cambridge grade. Full timed papers and human subject-teacher review remain outstanding. Cambridge states that 0984 has the same 2026–2028 subject content as 0478, with 9–1 grading. In June and November, Cambridge lists 0984 in Administrative zone 3 and for centres in Oman and the UAE. Confirm availability for your centre and exam series with Cambridge International. The separately published 2029–2031 syllabus changes to Python 3 only and removes pseudocode; this 2026–2028 route does not cover those changes.
Before you begin
- No programming language is required. Be comfortable with place value and multiplication; each lesson introduces the computer-science notation it uses.
Work on paper. Try each question before revealing help, and explain why your method works.
Quick readiness check
What does RLE use to represent a repeated sequence?
What you will learn
- Encode a repeated sequence using RLE
- Decode an RLE representation when its format is defined
- Explain why RLE works better on some data than others
Run-length encoding stores counts and values
RLE replaces a run of repeated symbols with a count and the symbol, such as AAAAA becoming 5A. The original sequence can be restored exactly when the encoding format is known, so RLE is lossless.
Apply and check the rule
RLE is effective when long runs repeat. If a file has many short, changing values, the count-and-symbol markers can be as large as or larger than the original. Compression is not guaranteed to reduce every file.
Pause and explain
Which sequence is most likely to benefit from RLE?
Worked example
Encode AAAAABBCC using the format count followed by symbol.
Show the worked solution
- There are five A symbols, then two B symbols, then two C symbols.
- Write each run as count and symbol.
- Join the three run codes.
Answer 5A2B2C
Try a topic test
Choose Easy, Normal or Difficult. Save your answers and open worked review after finishing.
Test this topic →From guided practice to a new situation
Write your answer and reasoning first. Use a hint only if you are stuck. The model solution is for self-checking; your written work is not automatically marked.
Encode BBBCCCCA using count-symbol RLE.
Give me a hint
Count consecutive runs, not total symbols of each kind.
Compare my reasoning
- BBB is a run of 3 B.
- CCCC is 4 C.
- A is a run of 1 A.
3B4C1A
Look for these in your work
- Runs separated correctly
- Counts correct
- Format consistent
Decode 2X5Y1Z using count-symbol RLE.
Give me a hint
Repeat each symbol the stated number of times.
Compare my reasoning
- 2X gives XX.
- 5Y gives YYYYY.
- 1Z gives Z.
XXYYYYYZ
Look for these in your work
- Each count applied
- Order preserved
- Decoded sequence correct
A bitmap row is 30 white pixels followed by 2 black pixels. Explain why RLE can reduce its storage, and name a case where RLE could be ineffective.
Give me a hint
Compare long repeated runs with changing values.
Compare my reasoning
- The 30 white pixels can be represented by a single count and colour.
- The two black pixels form another short run.
- A noisy row with constantly changing colours has few runs, so count markers may add overhead.
RLE can replace long repeated runs with compact count-value pairs. A noisy sequence with little repetition may not compress well and could grow due to the markers.
Look for these in your work
- Long run benefit explained
- Second run recognized
- Ineffective case explained
Common mistakes
- Counting symbols individually instead of counting each consecutive run
- Assuming RLE always makes the data shorter
What can you explain now?
How is AAAA represented by count-symbol RLE?
Compare with the explanation
4A
Four consecutive A symbols form one run.
After trying it yourself, choose your next review. This is your self-assessment.
Your review choice appears on Today. Sign in to sync it across devices.
Make it stick
Why can a lossless RLE file be larger than the original for data with few repeated values?
If you needed the solution, close it and solve the problem again from a blank page. A correct answer is stronger when you can explain the reason for each step.