Huffman Coding — Greedy Optimal Prefix Code

Merge the two lowest-frequency nodes via a min-heap until one tree remains

Input

Run

Speed

Min-heap (smallest first)

Result

Symbols n
5
Length N
11
Huffman bits
—
Fixed bits
—
Entropy H
—
Saving
—

Log

Huffman tree (left = 0, right = 1)

leaf (symbol) merged node active in this step edge bit

Code table

Explanation

Load text and press Run all to count frequencies, repeatedly merge the two smallest nodes from the min-heap, and read the optimal prefix code off the tree.