Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Find a Huffman encoding from a string
| ResourceFunction["HuffmanEncode"]["string"] gives an optimal binary Huffman encoding for a string. | 
| "Symbols" | unique symbols in the input string | 
| "CodeWords" | binary code words corresponding to each symbol | 
| "Encoding" | the Huffman-encoded version of the string | 
Find the Huffman encoding for a string:
| In[1]:= | ![ResourceFunction[
 "HuffmanEncode"]["compression is based on redundancy"]](https://www.wolframcloud.com/obj/resourcesystem/images/877/877ae346-afde-441f-af5d-73561ceeaeb4/6f9fa2de3f7d1ca9.png) | 
| Out[1]= |  | 
Use the resource function HuffmanDecode to decode the Huffman encoding:
| In[2]:= | ![ResourceFunction["HuffmanDecode"][%]](https://www.wolframcloud.com/obj/resourcesystem/images/877/877ae346-afde-441f-af5d-73561ceeaeb4/02e2c9ad1f4e5f79.png) | 
| Out[2]= |  | 
The resource function HuffmanDecode is the inverse of HuffmanEncode:
| In[3]:= | ![encoded = ResourceFunction["HuffmanEncode"]["the cat in the hat"]](https://www.wolframcloud.com/obj/resourcesystem/images/877/877ae346-afde-441f-af5d-73561ceeaeb4/5674f7e5135f02a9.png) | 
| Out[3]= |  | 
| In[4]:= | ![ResourceFunction["HuffmanDecode"][encoded]](https://www.wolframcloud.com/obj/resourcesystem/images/877/877ae346-afde-441f-af5d-73561ceeaeb4/0c1bc22093d0d1b8.png) | 
| Out[4]= |  | 
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License