Compression (Copy)
Cheat Sheet: A Level Computer Science – Data Compression
1. Need for Compression
- Purpose: Reduce file size for:
- Faster transmission over networks
- Less storage space
- Quicker loading times
- Trade-off: Compression may reduce quality or limit functionality depending on method used
2. Types of Compression
Lossless Compression
- Definition: No data lost during compression; original file can be perfectly reconstructed
- Examples:
- ZIP files
- PNG images
- FLAC audio
- Use When: Original quality must be preserved (e.g., text files, source code, critical images)
Lossy Compression
- Definition: Some data is permanently removed to reduce file size
- Examples:
- JPEG (images)
- MP3 (audio)
- MP4 (video)
- Use When: Slight loss of quality is acceptable (e.g., streaming, web media)
3. Justification of Compression Method
| File Type | Recommended Compression | Reason |
|---|---|---|
| Text Files | Lossless | Must retain all characters exactly |
| Bitmap Images | Lossy (e.g., JPEG) or Lossless (e.g., PNG) | JPEG for photos (smaller size), PNG for exact detail |
| Vector Graphics | Lossless | Vector data is precise & instruction-based |
| Sound Files | Lossy (e.g., MP3) or Lossless (e.g., FLAC) | MP3 for general use, FLAC for studio-quality audio |
4. Run-Length Encoding (RLE)
How It Works
- Compresses repeated data by storing value once and count of repetition
- Works best with long runs of identical data
Example
Original Data: AAAAABBBBCCCCCD
RLE Encoded: 5A4B5C1D
Applications
- Text Files: Repeating characters (e.g., spaces, tabs)
- Bitmap Images: Consecutive pixels with same colour
- Vector Graphics: Repeating shapes or fills
- Sound Files: Silent sections or flat wave segments
Limitations
- Not efficient for files with high variability (e.g., photographic images or natural sound)
