Frequencies a:45 b:13 c:12 d:16 e:9 f:5 — Huffman coding
introthe textbook six-symbol example
Answer
average 2.2400 bits/symbol, 224 bits total
Why this example is worth doing
The standard example from Cormen, Leiserson, Rivest and Stein, included so that a student can check this tool against the book they already own. The algorithm repeatedly merges the two least frequent nodes, so the rarest symbols end up deepest and therefore longest. Against a fixed three-bit code the saving is about a quarter, and the page shows the merge order as a numbered list because the order is what an exam asks you to reproduce.
Try your own input in the Huffman coding. Build the tree from text or from frequencies, with the merge order and canonical codes.
How the answer is reached
Codebook
| symbol | code |
|---|---|
| a | 0 |
| c | 100 |
| b | 101 |
| f | 1100 |
| e | 1101 |
| d | 111 |
Merge order
| step | left | right | weight |
|---|---|---|---|
| 1 | 5 | 9 | 14 |
| 2 | 12 | 13 | 25 |
| 3 | 14 | 16 | 30 |
| 4 | 25 | 30 | 55 |
| 5 | 45 | 55 | 100 |