Wolfram Computation Meets Knowledge

HuffmanDecode

Contributed by: Stephen Wolfram

Decode data specified by a Huffman encoding.

ResourceFunction["HuffmanDecode"][assoc]

decodes an association representing a Huffman encoding.

Details and Options

From A New Kind of Science, page 1071.

Examples

Basic Examples

Decode a Huffman encoding:

In[1]:=
ResourceFunction[
 "HuffmanDecode"][<|"Symbols" -> {" ", "a", "b", "c", "d", "e", "i", "m", "n", "o", "p", "r", "s", "u", "y"}, "CodeWords" -> {{0, 0, 1}, {0, 0, 0, 1}, {1, 0, 1, 1, 0}, {1, 0, 0, 0}, {1, 1, 0, 1}, {1, 1, 1, 0}, {1, 0, 0, 1}, {1, 0, 1, 1, 1}, {0, 1, 0}, {1, 1, 1, 1}, {1, 1, 0, 0, 0}, {1, 0, 1, 0}, {0, 1, 1}, {1, 1, 0, 0, 1}, {0, 0, 0, 0}}, "Encoding" -> {1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0,
     1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1,
     0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0,
     0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0,
     1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1,
     0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0}|>]
Out[1]=

Resource History