Run Length Encoding & Dictionary Coding Simplified Revision Notes for A-Level OCR Computer Science
Revision notes with simplified explanations to understand Run Length Encoding & Dictionary Coding quickly and effectively.
Learn about Compression, Encryption & Hashing for your A-Level Computer Science Exam. This Revision Note includes a summary of Compression, Encryption & Hashing for easy recall in your Computer Science exam
349+ students studying
Compression, Encryption & Hashing Quizzes
Test your knowledge with quizzes.
Compression, Encryption & Hashing Flashcards
Practice with bite-sized questions.
Compression, Encryption & Hashing Questions by Topic
Prepare with real exam question.
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: 3A4B5C3DExplanation:
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
Aspect
Run-Length Encoding (RLE)
Dictionary Coding
Compression Method
Encodes repeating sequences as value + count
Replaces patterns with dictionary-based codes
Best For
Simple images or text with long repetitions
Text files or data with recurring patterns
Data Structure
No additional data structure required
Requires a dictionary
Efficiency
High for simple, repetitive data
High for complex data with repeated patterns
Drawbacks
Ineffective for varied data
Increased 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.
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 For their A-Level Exams.
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