Photo AI

Last Updated Sep 27, 2025

Run Length Encoding & Dictionary Coding Simplified Revision Notes

Revision notes with simplified explanations to understand Run Length Encoding & Dictionary Coding quickly and effectively.

user avatar
user avatar
user avatar
user avatar
user avatar

439+ students studying

Run Length Encoding & Dictionary Coding

Overview

Compression is the process of reducing the size of data files, making storage and transmission more efficient. Two common compression techniques are Run-Length Encoding (RLE) and Dictionary Coding. These algorithms reduce file sizes in different ways and are often used for specific types of data. Understanding how these techniques work can help you recognise which is best suited to a given file type and application.

Run-Length Encoding (RLE)

What is Run-Length Encoding?

  • Run-length encoding (RLE) is a simple compression algorithm that reduces file size by identifying sequences of repeated data (runs) and encoding them as a single data value and a count.
  • This technique is effective when there are long sequences of repeated values, such as in simple images with large areas of the same color or text files with repeating characters.

How RLE Works

  • RLE identifies consecutive identical elements in the data, known as "runs."
  • Each run is stored as a single value and a count that represents how many times the value repeats.
lightbulbExample

Example:

  • Original string: AAABBBBCCCCCDDD
  • RLE compressed: 3A4B5C3D Explanation:

Instead of storing each character individually, RLE stores the character followed by the number of times it repeats. This reduces storage for long sequences.

Applications of RLE

  • Images: RLE is commonly used in bitmap images where pixels of the same colour are grouped together. For example, an image with a large area of white pixels can be compressed by representing the pixel colour and the count of pixels in each sequence.
  • Text Files: RLE can be applied to text with repeating characters, though it's less effective for natural language text with fewer repetitions.

Benefits and Drawbacks of RLE

Benefits:

  • Simple and Fast: RLE is easy to implement and efficient for encoding data with long runs of the same value.
  • Good for Specific Data: RLE works well for simple images or data with many repeating values.

Drawbacks:

  • Limited Usefulness: If there are few or no repeating values, RLE may increase file size instead of reducing it.
  • Not Effective for Complex Data: RLE doesn't compress well for data with varied or non-repetitive content.

RLE Example in Images

lightbulbExample

Example:

  • Consider a simple grayscale image row: 11111100000011111111
  • RLE compressed version: 6 1, 6 0, 8 1
  • Explanation: This version records each run of repeated pixels, dramatically reducing storage for images with large uniform areas.

Dictionary Coding

What is Dictionary Coding?

  • Dictionary Coding is a compression technique that reduces file size by replacing repeated data patterns with shorter, unique codes.
  • A dictionary is created where each unique pattern (e.g., a word, phrase, or symbol) in the data is stored with a code. The file is then rewritten using these shorter codes instead of the full patterns.

How Dictionary Coding Works

  • Step 1: Analyse the data to identify unique patterns (such as words in a text).
  • Step 2: Assign each unique pattern a code and store these in a dictionary.
  • Step 3: Replace each occurrence of the pattern in the data with its corresponding code.
lightbulbExample

Example: Original text: "this is a test. this is only a test."

Dictionary:

  • 1: "this"
  • 2: "is"
  • 3: "a"
  • 4: "test"
  • 5: "only" Compressed data: 1 2 3 4. 1 2 5 3 4.

Applications of Dictionary Coding

  • Text Files: Dictionary coding is commonly used for text compression, especially when there are recurring words or phrases.
  • File Compression Formats: Dictionary coding forms the basis of popular compression formats like ZIP and LZW (used in GIF images). These formats replace patterns of bytes with shorter codes to achieve compression.

Benefits and Drawbacks of Dictionary Coding

Benefits:

  • Effective for Repeated Patterns: Ideal for data with recurring words or sequences, such as text files or certain images.
  • Adaptable: Dictionary coding can be dynamically built and optimised during compression, making it versatile.

Drawbacks:

  • Memory Overhead: Storing the dictionary adds memory usage, especially for data with many unique patterns.
  • Initial Complexity: Dictionary coding is more complex to implement than RLE, as it requires building and managing a dictionary.

Dictionary Coding Example with LZW (Simplified)

lightbulbExample

Example:

  • Original string: ABABABABA
  • Initial dictionary:
  • A = 1, B = 2, AB = 3
  • Compression result (codes): 1 2 3 3
  • Explanation: The dictionary replaces repeating patterns with shorter codes, reducing the amount of data that needs to be stored.

Comparison Table

AspectRun-Length Encoding (RLE)Dictionary Coding
Compression MethodEncodes repeating sequences as value + countReplaces patterns with dictionary-based codes
Best ForSimple images or text with long repetitionsText files or data with recurring patterns
Data StructureNo additional data structure requiredRequires a dictionary
EfficiencyHigh for simple, repetitive dataHigh for complex data with repeated patterns
DrawbacksIneffective for varied dataIncreased memory usage for large dictionaries

Choosing Between RLE and Dictionary Coding

Simple Images (e.g., Monochrome Bitmaps)

  • Recommended Compression: Run-Length Encoding (RLE)
  • Reason: Large blocks of uniform colour make RLE highly effective for simple image formats.

Text Files with Repeated Words (e.g., Documents or Logs)

  • Recommended Compression: Dictionary Coding
  • Reason: Repeated words and phrases are best compressed by replacing them with shorter codes in a dictionary.

High-Resolution Images (e.g., Photographs)

  • Recommended Compression: Neither RLE nor Dictionary Coding alone
  • Reason: High-resolution images have complex colour patterns and do not typically benefit from either RLE or dictionary-based compression. Instead, other image compression methods like JPEG are more suitable.
infoNote

Key Takeaways

  • Run-length encoding (RLE) is effective for data with long runs of identical values, such as simple images with uniform colours. It's fast and easy to implement but not effective for complex or varied data.
  • Dictionary Coding replaces recurring data patterns with shorter codes, making it ideal for text compression and data with frequent repetitions. It is more memory-intensive but very effective for data with many repeated patterns.
  • Choosing the right compression technique depends on the nature of the data and the need for efficient storage and transmission.
Books

Only available for registered users.

Sign up now to view the full note, or log in if you already have an account!

500K+ Students Use These Powerful Tools to Master Run Length Encoding & Dictionary Coding

Enhance your understanding with flashcards, quizzes, and exams—designed to help you grasp key concepts, reinforce learning, and master any topic with confidence!

40 flashcards

Flashcards on Run Length Encoding & Dictionary Coding

Revise key concepts with interactive flashcards.

Try Computer Science Flashcards

4 quizzes

Quizzes on Run Length Encoding & Dictionary Coding

Test your knowledge with fun and engaging quizzes.

Try Computer Science Quizzes

29 questions

Exam questions on Run Length Encoding & Dictionary Coding

Boost your confidence with real exam questions.

Try Computer Science Questions

27 exams created

Exam Builder on Run Length Encoding & Dictionary Coding

Create custom exams across topics for better practice!

Try Computer Science exam builder

12 papers

Past Papers on Run Length Encoding & Dictionary Coding

Practice past papers to reinforce exam experience.

Try Computer Science Past Papers

Other Revision Notes related to Run Length Encoding & Dictionary Coding you should explore

Discover More Revision Notes Related to Run Length Encoding & Dictionary Coding to Deepen Your Understanding and Improve Your Mastery

96%

114 rated

Compression, Encryption & Hashing

Lossy & Lossless Compression

user avatar
user avatar
user avatar
user avatar
user avatar

385+ studying

191KViews

96%

114 rated

Compression, Encryption & Hashing

Symmetric vs Asymmetric Encryption

user avatar
user avatar
user avatar
user avatar
user avatar

229+ studying

197KViews

96%

114 rated

Compression, Encryption & Hashing

Hashing

user avatar
user avatar
user avatar
user avatar
user avatar

219+ studying

196KViews
Load more notes

Join 500,000+ A-Level students using SimpleStudy...

Join Thousands of A-Level Students Using SimpleStudy to Learn Smarter, Stay Organized, and Boost Their Grades with Confidence!

97% of Students

Report Improved Results

98% of Students

Recommend to friends

500,000+

Students Supported

50 Million+

Questions answered