Huffman Compression

Project Description

This project implements Huffman coding to generate prefix-free, variable-length codes based on the frequency of symbols in a given input. It supports both encoding and decoding, with validation tests to ensure the original data can be perfectly reconstructed.

Project Phases

  1. Analyzing symbol frequencies in the input text
  2. Building the Huffman tree from those frequencies
  3. Generating prefix codes from the tree structure
  4. Implementing the encoding pipeline
  5. Decoding encoded data and verifying correctness
  6. Evaluating overall compression performance

Summary of Analysis

Huffman compression performed consistently well across all tested files, with results largely influenced by how closely the frequency model matched the input text.

Across experiments, the average compression ratio was about 0.614, with a standard deviation of 0.047.

The best results were seen when each file was compressed using its own frequency distribution—for example, texts like “War and Peace” and “The Cat in the Hat” produced especially strong compression.

Even when using cross-file frequency models, performance remained solid overall, which suggests that natural language tends to share similar statistical patterns across different sources.

If a single universal model is chosen, the frequency distribution from “War and Peace” performed the most reliably, producing an average compression ratio of around 0.60.

Huffman Analysis Report
Download PDF

Key Learnings

  • Compression performance is strongly influenced by symbol frequency distributions (This is pretty fundamental).
  • Huffman coding translates statistical patterns into efficient prefix-free representations.
  • Natural language tends to preserve consistent redundancy across different texts.
  • Frequency models from one domain can still generalize reasonably well to others. (i.e., one huffman compression will often work moderately ok for another file).
Huffman Reflection
Download PDF
← Back to ADEN Course