Compression
Compression
3 KC5)
By
T.A Mubonderi
intro
https://www.youtube.com/watch?v=XcuJukkYRA8
2.1 What is Data Compression?
Benefits of Compression:
Faster file transfer over networks.
Reduced storage space requirements.
Lower bandwidth consumption
2.2 Types of Compression
There are two main types of compression:
1. Lossless Compression
Definition: Compression technique where no data is lost, and the original data can be perfectly restored.
Common methods:
Run-Length Encoding (RLE) – Replaces repeated values with a single value and a count.
Example: AAAAABBBCC → 5A3B2C
Huffman Coding – Assigns shorter binary codes to frequently used characters.
Dictionary-Based (LZW) – Stores patterns of data in a dictionary and replaces recurring sequences with dictionary indices.
Examples of lossless compression file formats:
PNG (images)
ZIP (files)
FLAC (audio)
Advantages:
No loss of quality.
Ideal for text and critical data (e.g., medical images).
Disadvantages:
Less effective for multimedia files with complex data patterns.
• 2. Lossy Compression
• Definition: Compression technique where some data is discarded to achieve higher compression
ratios.
• Common methods:
• JPEG (Joint Photographic Experts Group) – Reduces image quality by discarding minor details.
• MP3 (MPEG Audio Layer 3) – Removes frequencies beyond human hearing.
• MPEG (Moving Picture Experts Group) – Compresses video by discarding redundant frames.
• Examples of lossy compression file formats:
• JPEG (images)
• MP3 (audio)
• MP4 (video)
• Advantages:
• Significant reduction in file size.
• Suitable for multimedia content (e.g., music, videos).
• Disadvantages:
• Loss of data quality (may introduce artifacts).
• Not suitable for critical data (e.g., legal documents).
compare
Example:
Original size = 10MB, Compressed size = 2MB
Compression ratio = 102=5:1\frac{10}{2} = 5:1210=5:1
A higher ratio means better compression but may lead to quality loss
(for lossy methods).
2.6 Considerations for Choosing Compression
Techniques