Compare compression ratios across different algorithms
| Algorithm | Compressed Size | Compression Ratio | Space Saved | Efficiency |
|---|
How RLE Works: Consecutive identical characters are encoded as [count][character]
Example: "AAABBB" → "3A3B"
| Character | ASCII/Unicode | Frequency | Percentage |
|---|
Huffman Coding: Variable-length codes based on character frequency. More frequent characters get shorter codes.
| Character | Frequency | Code | Code Length |
|---|
Best for: Data with many consecutive repeated characters (images, simple graphics)
How it works: Replaces runs of identical characters with a count and the character
Example: "WWWWWWWW" → "8W"
Weakness: Can increase size if data has few repeating characters
Best for: Text and general data with varying character frequencies
How it works: Builds a binary tree based on character frequencies, assigns shorter codes to frequent characters
Example: Frequent 'e' might be "10", rare 'z' might be "110010"
Advantage: Optimal prefix-free code for known frequency distribution
Best for: Text with repeated phrases or patterns
How it works: References previously seen sequences using (distance, length) pairs
Example: "the cat and the dog" - second "the" references first occurrence
Used in: ZIP, GZIP, PNG compression
Best for: Maximum compression efficiency
How it works: Represents entire message as a single number in range [0,1)
Advantage: Can achieve better compression than Huffman
Used in: JPEG 2000, H.264 video compression
Compression Ratio:
Ratio = (Compressed Size / Original Size) × 100%
Lower is better. 50% means compressed to half the original size.
Space Saved:
Space Saved = Original Size - Compressed Size
Shows absolute reduction in bytes or bits.
Compression Efficiency:
Efficiency = ((Original Size - Compressed Size) / Original Size) × 100%
Higher is better. 50% efficiency means you saved half the space.
Important Notes:
Use RLE when:
Use Huffman when:
Use Dictionary-Based (LZ77) when:
Use Arithmetic when: