Back to projectsProject archive

Huffman Coding

Implementation of Huffman coding that compares fixed-length encoding against frequency-based compression with explicit space savings.

Context

Created as a compression-focused data structures exercise around a classic question: how to encode the same message with fewer bits when symbol frequency is uneven.

Problem

Using a fixed-length representation wastes space when some symbols appear far more often than others, so the project needed a way to compress text without losing information.

Solution

The program calculates symbol frequencies, builds a Huffman tree, maps each symbol to a variable-length code, and reports the encoded output alongside the space saved versus the original representation.

Key decisions

  • -Used a binary-tree representation to make the compression process transparent and traceable.
  • -Reported both the encoded string and the savings percentage so the benefit is measurable, not implied.
  • -Kept the workflow input-driven around a text file to match the assignment's reproducible setup.

Key features

  • -Frequency analysis over the input message
  • -Huffman tree construction for variable-length encoding
  • -Generated code map for each symbol
  • -Comparison between original and compressed bit usage

Results

  • -Makes the value of Huffman coding visible with concrete compression output.
  • -Shows comfort with trees, encoding logic, and algorithmic reporting.
  • -Strengthens the portfolio's lower-level computer science work.

Stack

JavaData StructuresAlgorithmsBinary Trees

Links