Wolfram Computation Meets Knowledge

HuffmanCodeWords

Contributed by: Stephen Wolfram

Find optimal Huffman code words given a list of probabilities.

ResourceFunction["HuffmanCodeWords"][list]

gives optimal binary Huffman code words corresponding to probabilities in the specified list.

Details and Options

From A New Kind of Science, page 1071.

Examples

Basic Examples

Generate a list of code words:

In[1]:=
ResourceFunction["HuffmanCodeWords"][{1/2, 1/4, 1/8, 1/8}]
Out[2]=

Get code words from a Wikipedia article for letter frequency of the whole alphabet:

In[3]:=
KeyTake[LetterCounts[WikipediaData["computer"]], Alphabet[]]
Out[3]=
In[4]:=
ResourceFunction["HuffmanCodeWords"][Values[%]]
Out[5]=
In[6]:=
AssociationThread[Alphabet[] -> %]
Out[6]=

Resource History