Why it matters

Huffman is classic greedy. Understanding shapes compression.

Advertisement

The architecture

Min-PQ by frequency.

Merge two smallest.

Repeat until one tree.

Huffman flowMin-PQby frequencyMerge two smallestcombineRepeatuntil one treeAdaptive Huffman + arithmetic coding refine; DEFLATE combines Huffman + LZ77
Huffman.
Advertisement

How it works end to end

Prefix code (no code prefix of another).

Minimizes expected code length.

O(n log n) with PQ.