Diego Malagrida Huffman File Compressor ↑ Top

Authors Diego Malagrida GonzálezAndreu Massanet Felix

Published1 May 2026

Sectionalgorithms

Huffman File Compressor

A desktop compressor built on the greedy Huffman algorithm, with the code tree drawn on screen and four priority queues raced against each other.

The application window with the Huffman code tree drawn as a graph of green nodes, and the compression panel beside it.
The code tree built for a file, drawn as the archive is written.

Overview

A Java Swing application that compresses and decompresses files and whole directories with Huffman coding, draws the resulting code tree, and benchmarks the priority-queue implementations used to build it.

Huffman coding is the textbook greedy algorithm: count how often each symbol appears, put every symbol in a priority queue keyed by frequency, and merge the two least frequent nodes over and over until one tree is left. Frequent symbols come out with short bit codes, so the encoded file approaches the entropy of the source. The application builds that tree, encodes the payload into a bitstream, writes a self-describing archive (header, codes, bits) and decodes it back to a file identical to the original.

The priority queue is the part that decides how long building the tree takes, so it is interchangeable: four implementations are measured against each other over the same input, which turns the practice into a benchmark rather than a single answer.

Project 4 of 7 for the Advanced Algorithms course at the Universitat de les Illes Balears, the one on greedy algorithms.

javagreedy-algorithmsdata-compression

← All projects