Signed up recently but had issues with the confirmation email?

Click Forgot password and follow the reset steps. You can choose the same password you used when you signed up. This should then provide access.

Remember to check Spam and Junk. The email will be from auth@progressbytes.co.uk.

Revision notesQuestionsFor schools
Revise Computing
Log inStart revising free
Revision notesQuestionsFor schoolsLog in

© 2026 Revise Computing · revisecomputing.co.uk

Worried about something?Question Bank UpdatesPrivacy noticeTermsContact

Revise Computing is an independent revision resource. It is not affiliated with, or endorsed by, OCR (Oxford Cambridge and RSA Examinations).

Knowledge/A Level/H446/01 Computer systems/Compression, Encryption and Hashing/Run length encoding and dictionary coding…

Run length encoding and dictionary coding for lossless compression

Run length encoding and dictionary coding for lossless compression.

1.3.1 Compression, Encryption and Hashing

Practise exam questions

Compression, Encryption and Hashing — Note 2 of 4

Candidates need to understand how run-length encoding can reduce the size of a file for example with a text file or image. Candidates should understand how dictionary coding works by substituting entries with a unique code. Candidates should have practical experience of using these algorithms with small example files.

What you need to know

Run length encoding and dictionary coding are two lossless compression methods. Both work by finding repetition in the data and storing it more efficiently, so the original can be rebuilt exactly.

What to know

  • RLE works well for data with long runs of the same value, e.g. simple images with large blocks of one colour.
  • RLE can make a file LARGER (or no smaller) if there are few repeated values, because every single value is then stored with a count as well. Ordinary text rarely has the same letter several times in a row, so RLE suits simple images far better than prose.
  • Dictionary coding works well for text with many repeated words. The dictionary itself takes up space, so it is less effective on short files.

Code examples

Run length encoding in Python
python
def rle(data):
    result = []
    count = 1
    for i in range(1, len(data) + 1):
        if i < len(data) and data[i] == data[i - 1]:
            count = count + 1
        else:
            result.append(str(count) + data[i - 1])
            count = 1
    return " ".join(result)

print(rle("WWWWWBBBWW"))   # 5W 3B 2W
Dictionary coding example
text
Text:        the cat sat on the mat the end
Dictionary:  1 = the   2 = cat   3 = sat   4 = on   5 = mat   6 = end
Encoded:     1 2 3 4 1 5 1 6

Key terms

Run length encodingRLE

Replaces a run of repeated values with a single copy of the value and a count of how many times it repeats.

Dictionary coding

Frequently occurring words or patterns are replaced by shorter codes, and a dictionary that maps codes to the original patterns is stored with the file.

Exam technique

  • Tip:You may also be asked to DECOMPRESS: expand each value-count pair back into its run, so 5W 3B 2W becomes WWWWWBBBWW. On an image grid, shading or letters are both fine as long as every run is clear.
  • Tip:To encode text with a given dictionary, work from left to right, matching the dictionary's entries in order so that every character is covered, and write each code. If the dictionary has a code for a space, every space needs its code too: a missed single space is the most common slip.
  • Tip:You should be able to apply both methods to a small example and work out the compressed result. In a 'discuss and recommend' question, apply BOTH to the data given, compare the savings and justify your choice from them.
  • Example:RLE on the row WWWWWBBBWW gives 5W 3B 2W (or W5B3W2), reducing 10 values to 3 value-count pairs.

Past exam questions

  • June 2026Paper 1Q3(e)6marks
  • June 2025Paper 1Q7(b)4marks
  • June 2019Paper 1Q2(b)2marks
  • June 2019Paper 1Q2(c)3marks
  • June 2017Paper 1Q3(b)12marks

Ready to test yourself?

Practise 1.3.1 questions
← Previous noteLossy vs lossless compression1.3.1 Compression, Encryption and HashingNext note →Symmetric and asymmetric encryption1.3.1 Compression, Encryption and Hashing

Back to Compression, Encryption and Hashing

Compression, Encryption and Hashing

Note 2 of 4

  1. 1Lossy vs lossless compression
  2. 2Run length encoding and dictionary coding for lossless compression
  3. 3Symmetric and asymmetric encryption
  4. 4Different uses of hashing
Topic overview