Skip to content

Huffman coding

planning ahead

Level 3 of 3

Also called Huffman code and Optimal prefix code.

Gives each letter of a text a code of 0s and 1s, short for letters used often and long for rare ones, with no code the start of another, so the bits read back without gaps. The two lightest trees are joined again and again until one tree holds every letter.

the queue, lightest at the front

the tree: 0 down to the left, 1 down to the right

comparisons to line the letters up
0
joins
0

step 1 of 1

Examples

A word of 2 to 12 letters a to z, with at most 6 different letters, for example abracadabra.